当前位置: 首页>>代码示例>>Java>>正文


Java TestUtils.assertEquals方法代码示例

本文整理汇总了Java中org.ojalgo.TestUtils.assertEquals方法的典型用法代码示例。如果您正苦于以下问题:Java TestUtils.assertEquals方法的具体用法?Java TestUtils.assertEquals怎么用?Java TestUtils.assertEquals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ojalgo.TestUtils的用法示例。


在下文中一共展示了TestUtils.assertEquals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMPSafiro

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * Defines a problem of 28 rows and 32 columns. Seems to be the same model as afiro at netlib. Netlib also
 * provides the solution.
 * <a href="http://www-new.mcs.anl.gov/otc/Guide/TestProblems/LPtest/netlib/afiro.html">[email protected]</a>
 * OK! 2010-04-19 lp_solve => -464.75314286
 */
public void testMPSafiro() {

    final File tmpFile = new File(PATH + "afiro.mps");
    final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
    final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();

    TestUtils.assertTrue(tmpModel.validate());

    final BigDecimal tmpExpVal = new BigDecimal("-.46475314286e+3");
    final double tmpActVal = tmpModel.minimise().getValue();
    TestUtils.assertEquals(tmpExpVal.doubleValue(), tmpActVal, PRECISION);

    if (!tmpModel.validate(PRECISION)) {
        TestUtils.fail(SOLUTION_NOT_VALID);
    }
}
 
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:23,代码来源:BurkardtDatasetsMps.java

示例2: testStratCombPortfolioMixer

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testStratCombPortfolioMixer() {

        final FinancePortfolio tmpTarget = new SimplePortfolio(THIRD, THIRD, THIRD).normalise();

        final FinancePortfolio tmpStrat1 = new SimplePortfolio(HALF, HALF, ZERO);
        final FinancePortfolio tmpStrat2 = new SimplePortfolio(HALF, ZERO, HALF);
        final FinancePortfolio tmpStrat3 = new SimplePortfolio(ZERO, HALF, HALF);

        final PortfolioMixer tmpMixer = new PortfolioMixer(tmpTarget, tmpStrat1, tmpStrat2, tmpStrat3);

        final int tmpExpectedNumberOfStrategies = 2;
        final List<BigDecimal> tmpStrategyWeights = tmpMixer.mix(tmpExpectedNumberOfStrategies);

        int tmpUseCount = 0;
        double tmpTotalWeight = 0D;

        for (final BigDecimal tmpWeight : tmpStrategyWeights) {
            if (tmpWeight.signum() != 0) {
                tmpUseCount++;
                tmpTotalWeight += tmpWeight.doubleValue();
            }
        }

        TestUtils.assertEquals(tmpExpectedNumberOfStrategies, tmpUseCount);
        TestUtils.assertEquals(PrimitiveMath.ONE, tmpTotalWeight, 1E-14 / PrimitiveMath.THREE);
    }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:27,代码来源:StrategyMixer.java

示例3: doCompare

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
void doCompare(final InverterTask<Double> fixed, final int dimension) {

        try {

            final MatrixStore<Double> tmpMatrix = this.makeSPD(dimension);

            final MatrixStore<Double> tmpExpInv = fixed.invert(tmpMatrix);

            final List<MatrixDecomposition<Double>> tmpList = MatrixDecompositionTests.getAllPrimitive();
            for (final MatrixDecomposition<Double> tmpDecomp : tmpList) {
                if (tmpDecomp instanceof InverterTask) {
                    @SuppressWarnings("unchecked")
                    final InverterTask<Double> tmpTask = (InverterTask<Double>) tmpDecomp;
                    final MatrixStore<Double> tmpActInv = tmpTask.invert(tmpMatrix);
                    TestUtils.assertEquals(tmpDecomp.getClass().getName(), tmpExpInv, tmpActInv);
                }
            }

        } catch (final RecoverableCondition exception) {
            TestUtils.fail(exception.getMessage());
        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:23,代码来源:InverterTest.java

示例4: testData

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * @see org.ojalgo.matrix.BasicMatrixTest#testData()
 */
@Override
public void testData() {

    final BasicMatrix tmpA = SimpleCholeskyCase.getOriginal();
    final BasicMatrix tmpL = SimpleCholeskyCase.getFactorL();
    final BasicMatrix tmpR = SimpleCholeskyCase.getFactorR();

    myExpMtrx = tmpL;
    myActMtrx = tmpR.transpose();

    TestUtils.assertEquals(myExpMtrx, myActMtrx, EVALUATION);

    myExpMtrx = tmpA;
    myActMtrx = tmpL.multiply(tmpR);

    TestUtils.assertEquals(myExpMtrx, myActMtrx, EVALUATION);
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:21,代码来源:SimpleCholeskyCase.java

示例5: _testCoshAndBackAgain

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void _testCoshAndBackAgain() {

        final double[] tmpArguments = new double[] { PrimitiveMath.NEG, PrimitiveMath.ZERO, PrimitiveMath.ONE };

        for (int s = 0; s < tmpArguments.length; s++) {
            for (int i = 0; i < tmpArguments.length; i++) {
                for (int j = 0; j < tmpArguments.length; j++) {
                    for (int k = 0; k < tmpArguments.length; k++) {

                        final Quaternion tmpOriginal = Quaternion.of(tmpArguments[s], tmpArguments[i], tmpArguments[j], tmpArguments[k]);

                        final Quaternion tmpOp = QuaternionFunction.COSH.invoke(tmpOriginal);
                        final Quaternion tmpInv = QuaternionFunction.ACOSH.invoke(tmpOriginal);

                        final Quaternion tmpInvOp = QuaternionFunction.ACOSH.invoke(tmpOp);
                        final Quaternion tmpOpInv = QuaternionFunction.COSH.invoke(tmpInv);

                        TestUtils.assertEquals(tmpOriginal, tmpInvOp);
                        TestUtils.assertEquals(tmpOriginal, tmpOpInv);
                    }
                }
            }
        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:25,代码来源:QuaternionTest.java

示例6: _testCosAndBackAgain

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void _testCosAndBackAgain() {

        final double[] tmpArguments = new double[] { PrimitiveMath.NEG, PrimitiveMath.ZERO, PrimitiveMath.ONE };

        for (int s = 0; s < tmpArguments.length; s++) {
            for (int i = 0; i < tmpArguments.length; i++) {
                for (int j = 0; j < tmpArguments.length; j++) {
                    for (int k = 0; k < tmpArguments.length; k++) {

                        final Quaternion tmpOriginal = Quaternion.of(tmpArguments[s], tmpArguments[i], tmpArguments[j], tmpArguments[k]);

                        final Quaternion tmpOp = QuaternionFunction.COS.invoke(tmpOriginal);
                        final Quaternion tmpInv = QuaternionFunction.ACOS.invoke(tmpOriginal);

                        final Quaternion tmpInvOp = QuaternionFunction.ACOS.invoke(tmpOp);
                        final Quaternion tmpOpInv = QuaternionFunction.COS.invoke(tmpInv);

                        TestUtils.assertEquals(tmpOriginal, tmpInvOp);
                        TestUtils.assertEquals(tmpOriginal, tmpOpInv);
                    }
                }
            }
        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:25,代码来源:QuaternionTest.java

示例7: testVarianceOfInvestorViewPortfolios

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testVarianceOfInvestorViewPortfolios() {

        final BasicMatrix tmpViews = BlackLittermanTest.getInvestorPortfoliosMatrix();
        final BasicMatrix tmpCovar = BlackLittermanTest.getCovariances();

        final BasicMatrix tmpExp = BlackLittermanTest.getVarianceOfInvestorViewPortfolios();
        final BasicMatrix tmpAct = tmpViews.multiply(tmpCovar).multiply(tmpViews.transpose());

        for (int i = 0; i < tmpExp.countRows(); i++) {
            final int row = i;
            final int row1 = i;
            final int col = i;
            TestUtils.assertEquals(TypeUtils.toBigDecimal(tmpExp.get(row, 0)), TypeUtils.toBigDecimal(tmpAct.get(row1, col)), EVAL_CNTXT);
        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:16,代码来源:BlackLittermanTest.java

示例8: testStratCombPortfolioMixerRandom

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testStratCombPortfolioMixerRandom() {

        final FinancePortfolio tmpTarget = new SimplePortfolio(QUARTER, QUARTER, QUARTER, QUARTER).normalise();

        final Uniform tmpGen = new Uniform();

        final FinancePortfolio tmpStrat1 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue())
                .normalise();
        final FinancePortfolio tmpStrat2 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue())
                .normalise();
        final FinancePortfolio tmpStrat3 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue())
                .normalise();

        final PortfolioMixer tmpMixer = new PortfolioMixer(tmpTarget, tmpStrat1, tmpStrat2, tmpStrat3);

        final int tmpExpectedNumberOfStrategies = 2;
        final List<BigDecimal> tmpStrategyWeights = tmpMixer.mix(tmpExpectedNumberOfStrategies);

        int tmpUseCount = 0;
        double tmpTotalWeight = 0D;

        for (final BigDecimal tmpWeight : tmpStrategyWeights) {
            if (tmpWeight.signum() != 0) {
                tmpUseCount++;
                tmpTotalWeight += tmpWeight.doubleValue();
            }
        }

        TestUtils.assertEquals(tmpExpectedNumberOfStrategies, tmpUseCount);
        TestUtils.assertEquals(PrimitiveMath.ONE, tmpTotalWeight, 1E-14 / PrimitiveMath.THREE / PrimitiveMath.HUNDRED);
    }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:32,代码来源:StrategyMixer.java

示例9: testP20160608

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * <a href="https://github.com/optimatika/ojAlgo/issues/23">GitHub Issue 23</a> The problem was that since
 * the model allows shorting the pure profit maximisation is unbounded (initial LP). The algorithm did not
 * handle the case where "target" could be >= the max possible when shorting not allowed (bounded LP).
 */
public void testP20160608() {

    final BasicMatrix.Factory<PrimitiveMatrix> matrixFactory = PrimitiveMatrix.FACTORY;
    final PrimitiveMatrix cov = matrixFactory.rows(new double[][] { { 0.01, 0.0018, 0.0011 }, { 0.0018, 0.0109, 0.0026 }, { 0.0011, 0.0026, 0.0199 } });
    final PrimitiveMatrix ret = matrixFactory.columns(new double[] { 0.0427, 0.0015, 0.0285 });

    final MarketEquilibrium marketEquilibrium = new MarketEquilibrium(cov);
    final MarkowitzModel markowitz = new MarkowitzModel(marketEquilibrium, ret);
    markowitz.setShortingAllowed(true);
    markowitz.setTargetReturn(BigDecimal.valueOf(0.0427));

    List<BigDecimal> tmpWeights = markowitz.getWeights();
    TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());

    final NumberContext tmpTestPrecision = StandardType.PERCENT.newPrecision(4);

    // Solution reachable without shorting, but since it is allowed the optimal solution is different
    TestUtils.assertEquals(0.82745, tmpWeights.get(0).doubleValue(), tmpTestPrecision); // 0.82745
    TestUtils.assertEquals(-0.09075, tmpWeights.get(1).doubleValue(), tmpTestPrecision); // -0.09075
    TestUtils.assertEquals(0.26329, tmpWeights.get(2).doubleValue(), tmpTestPrecision); // 0.26329

    TestUtils.assertEquals(0.0427, markowitz.getMeanReturn(), tmpTestPrecision);
    TestUtils.assertEquals(0.0084, markowitz.getReturnVariance(), tmpTestPrecision);

    // Also verify that it's posible to reach 10% return by shorting
    markowitz.setTargetReturn(BigDecimal.valueOf(0.1));
    TestUtils.assertEquals(0.1, markowitz.getMeanReturn(), tmpTestPrecision);
    TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());

    // Min risk portfolio, very high risk aversion means minimum risk.
    markowitz.setTargetReturn(null);
    markowitz.setRiskAversion(new BigDecimal(1000000));
    tmpWeights = markowitz.getWeights();
    TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());
    TestUtils.assertEquals(0.4411, tmpWeights.get(0).doubleValue(), tmpTestPrecision); // 0.4411
    TestUtils.assertEquals(0.3656, tmpWeights.get(1).doubleValue(), tmpTestPrecision); // 0.3656
    TestUtils.assertEquals(0.1933, tmpWeights.get(2).doubleValue(), tmpTestPrecision); // 0.1933
}
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:44,代码来源:PortfolioProblems.java

示例10: testGetNumberOfDimensions

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testGetNumberOfDimensions() {

        TestUtils.assertEquals(1, STRUCTURE_1D.length);
        TestUtils.assertEquals(2, STRUCTURE_2D.length);
        TestUtils.assertEquals(3, STRUCTURE_3D.length);
        TestUtils.assertEquals(4, STRUCTURE_4D.length);
    }
 
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:8,代码来源:ArrayStructureTest.java

示例11: testDailyComparison

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testDailyComparison() {

        final String tmpYahooSymbol = "AAPL";
        final String tmpGoogleSymbol = "NASDAQ:AAPL";

        final YahooSymbol tmpYahooSource = new YahooSymbol(tmpYahooSymbol, CalendarDateUnit.DAY);
        final CalendarDateSeries<Double> tmpYahooPrices = tmpYahooSource.getPriceSeries();

        final GoogleSymbol tmpGoogleSource = new GoogleSymbol(tmpGoogleSymbol, CalendarDateUnit.DAY);
        final CalendarDateSeries<Double> tmpGooglePrices = tmpGoogleSource.getPriceSeries();

        CoordinationSet<Double> tmpCoordinator = new CoordinationSet<>();
        tmpCoordinator.put(tmpYahooPrices);
        tmpCoordinator.put(tmpGooglePrices);
        tmpCoordinator.complete();
        tmpCoordinator = tmpCoordinator.prune();
        final CalendarDateSeries<Double> tmpPrunedYahoo = tmpCoordinator.get(tmpYahooSymbol);
        final CalendarDateSeries<Double> tmpPrunedGoogle = tmpCoordinator.get(tmpGoogleSymbol);

        TestUtils.assertEquals("count", tmpPrunedYahoo.size(), tmpPrunedGoogle.size());
        TestUtils.assertEquals("Last Value", tmpPrunedYahoo.lastValue(), tmpPrunedGoogle.lastValue(), NumberContext.getGeneral(8, 14));
        // Doesn't work. Goggle and Yahoo seemsto have different data
        // JUnitUtils.assertEquals("First Value", tmpPrunedYahoo.firstValue(), tmpPrunedGoogle.firstValue(), PrimitiveMath.IS_ZERO);

        //        for (final CalendarDate tmpKey : tmpCoordinator.getAllContainedKeys()) {
        //            final double tmpYahooValue = tmpPrunedYahoo.get(tmpKey);
        //            final double tmpGoogleValue = tmpPrunedGoogle.get(tmpKey);
        //            if (tmpYahooValue != tmpGoogleValue) {
        //                BasicLogger.logDebug("Date={} Yahoo={} Google={}", tmpKey, tmpYahooValue, tmpGoogleValue);
        //            }
        //        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:33,代码来源:SymbolDataTest.java

示例12: doTestCleaning

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
private static void doTestCleaning(final double[][] original) {

        final NumberContext tmpEvalCntx = NumberContext.getGeneral(6, 12);

        final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(original);

        final SingularValue<Double> tmpSVD = SingularValue.make(tmpOriginal);

        tmpSVD.decompose(tmpOriginal);
        final double tmpRefCond = tmpSVD.getCondition();
        final int tmpRefRank = tmpSVD.getRank();
        final double tmpRefNorm = tmpSVD.getFrobeniusNorm();

        final PrimitiveMatrix tmpCorrelations = FinanceUtils.toCorrelations(tmpOriginal, true);
        final PrimitiveMatrix tmpVolatilities = FinanceUtils.toVolatilities(tmpOriginal, true);
        final PrimitiveMatrix tmpCovariances = FinanceUtils.toCovariances(tmpVolatilities, tmpCorrelations);

        tmpSVD.decompose(PrimitiveDenseStore.FACTORY.copy(tmpCovariances));
        final double tmpNewCond = tmpSVD.getCondition();
        final int tmpNewRank = tmpSVD.getRank();
        final double tmpNewNorm = tmpSVD.getFrobeniusNorm();

        TestUtils.assertTrue("Improved the condition", tmpNewCond <= tmpRefCond);
        TestUtils.assertTrue("Improved the rank", tmpNewRank >= tmpRefRank);
        TestUtils.assertEquals("Full rank", original.length, tmpNewRank);
        TestUtils.assertEquals("Roughly the same frob norm", tmpRefNorm, tmpNewNorm, tmpEvalCntx);

        if (DEBUG) {
            BasicLogger.debug("Original", tmpOriginal);
            BasicLogger.debug("Cleaned", tmpCovariances);
            BasicLogger.debug("Difference", tmpOriginal.subtract(PrimitiveDenseStore.FACTORY.copy(tmpCovariances)), tmpEvalCntx);
        }

    }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:35,代码来源:FinanceUtilsTest.java

示例13: testInverseOfRandomCase

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testInverseOfRandomCase() {

        final NumberContext tmpEqualsNumberContext = new NumberContext(7, 10);

        final int tmpDim = 99;
        final PhysicalStore<Double> tmpRandom = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
        final PhysicalStore<Double> tmpIdentity = PrimitiveDenseStore.FACTORY.makeEye(tmpDim, tmpDim);

        final MatrixDecomposition.Solver<Double>[] tmpAllDecomps = TestSolveAndInvert.getAllSquare();

        final LU<Double> tmpRefDecomps = new RawLU();
        tmpRefDecomps.decompose(tmpRandom);
        final MatrixStore<Double> tmpExpected = tmpRefDecomps.getInverse();

        for (final MatrixDecomposition.Solver<Double> tmpDecomp : tmpAllDecomps) {
            final String tmpName = tmpDecomp.getClass().getName();

            if (MatrixDecompositionTests.DEBUG) {
                BasicLogger.debug(tmpName);
            }

            tmpDecomp.decompose(tmpRandom);

            final MatrixStore<Double> tmpActual = tmpDecomp.getInverse();

            TestUtils.assertEquals(tmpName, tmpExpected, tmpActual, tmpEqualsNumberContext);
            TestUtils.assertEquals(tmpName, tmpIdentity, tmpActual.multiply(tmpRandom), tmpEqualsNumberContext);
            TestUtils.assertEquals(tmpName, tmpIdentity, tmpRandom.multiply(tmpActual), tmpEqualsNumberContext);
        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:31,代码来源:TestSolveAndInvert.java

示例14: testMath272

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testMath272() {
    final LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 2, 2, 1 }, 0);
    final Collection<LinearConstraint> constraints = new ArrayList<>();
    constraints.add(new LinearConstraint(new double[] { 1, 1, 0 }, Relationship.GEQ, 1));
    constraints.add(new LinearConstraint(new double[] { 1, 0, 1 }, Relationship.GEQ, 1));
    constraints.add(new LinearConstraint(new double[] { 0, 1, 0 }, Relationship.GEQ, 1));

    final SimplexSolver solver = new SimplexSolver();
    final PointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, true);

    TestUtils.assertEquals(0.0, solution.getPoint()[0], .0000001);
    TestUtils.assertEquals(1.0, solution.getPoint()[1], .0000001);
    TestUtils.assertEquals(1.0, solution.getPoint()[2], .0000001);
    TestUtils.assertEquals(3.0, solution.getValue(), .0000001);
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:16,代码来源:CommonsMathSimplexSolverTest.java

示例15: testProblem

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
@Override
public void testProblem() {

    final BasicMatrix tmpMatrix = P20061119Case.getProblematic();

    final Eigenvalue<Double> tmpEigenvalue = Eigenvalue.PRIMITIVE.make();
    final PhysicalStore<Double> tmpPrimitiveStore = PrimitiveDenseStore.FACTORY.copy(tmpMatrix);
    tmpEigenvalue.decompose(tmpPrimitiveStore);

    TestUtils.assertEquals(tmpPrimitiveStore, tmpEigenvalue, EVALUATION);
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:12,代码来源:P20061119Case.java


注:本文中的org.ojalgo.TestUtils.assertEquals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。