Skip to content

Commit

Permalink
Merge 7103514 into 858ecda
Browse files Browse the repository at this point in the history
  • Loading branch information
arturobernalg committed Aug 10, 2021
2 parents 858ecda + 7103514 commit 2509ce8
Show file tree
Hide file tree
Showing 52 changed files with 234 additions and 251 deletions.
Expand Up @@ -522,10 +522,10 @@ public void testEquals() {
T t1a = build(1.0);
T t1b = build(1.0);
T t2 = build(2.0);
Assert.assertTrue(t1a.equals(t1a));
Assert.assertTrue(t1a.equals(t1b));
Assert.assertFalse(t1a.equals(t2));
Assert.assertFalse(t1a.equals(new Object()));
Assert.assertEquals(t1a, t1a);
Assert.assertEquals(t1a, t1b);
Assert.assertNotEquals(t1a, t2);
Assert.assertNotEquals(t1a, new Object());
}

@Test
Expand Down
Expand Up @@ -39,26 +39,26 @@ public void testAccessor2() {

// Check that both APIs refer to the same data.

Assert.assertTrue(p.getFirst() == p.getKey());
Assert.assertTrue(p.getSecond() == p.getValue());
Assert.assertSame(p.getFirst(), p.getKey());
Assert.assertSame(p.getSecond(), p.getValue());
}

@Test
public void testEquals() {
Pair<Integer, Double> p1 = new Pair<>(null, null);
Assert.assertFalse(p1.equals(null));
Assert.assertNotEquals(null, p1);

Pair<Integer, Double> p2 = new Pair<>(null, null);
Assert.assertTrue(p1.equals(p2));
Assert.assertEquals(p1, p2);

p1 = new Pair<>(new Integer(1), new Double(2));
Assert.assertFalse(p1.equals(p2));
Assert.assertNotEquals(p1, p2);

p2 = new Pair<>(new Integer(1), new Double(2));
Assert.assertTrue(p1.equals(p2));
Assert.assertEquals(p1, p2);

Pair<Integer, Float> p3 = new Pair<>(new Integer(1), new Float(2));
Assert.assertFalse(p1.equals(p3));
Assert.assertNotEquals(p1, p3);
}

@Test
Expand All @@ -69,11 +69,11 @@ public void testHashCode() {
final Pair<MyInteger, MyInteger> p1 = new Pair<>(m1, m1);
final Pair<MyInteger, MyInteger> p2 = new Pair<>(m2, m2);
// Same contents, same hash code.
Assert.assertTrue(p1.hashCode() == p2.hashCode());
Assert.assertEquals(p1.hashCode(), p2.hashCode());

// Different contents, different hash codes.
m2.set(2);
Assert.assertFalse(p1.hashCode() == p2.hashCode());
Assert.assertNotEquals(p1.hashCode(), p2.hashCode());
}

@Test
Expand Down
Expand Up @@ -1433,12 +1433,12 @@ public void testIntPowSpecialCases() {
// Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting zero.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
assertTrue(AccurateMath.pow(d, Long.MIN_VALUE + 1L) == 0.0);
assertEquals(0.0, AccurateMath.pow(d, Long.MIN_VALUE + 1L), 0.0);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
assertTrue(AccurateMath.pow(d, Long.MAX_VALUE) == 0.0);
assertEquals(0.0, AccurateMath.pow(d, Long.MAX_VALUE), 0.0);
}
}
// If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. <- Impossible with int.
Expand Down Expand Up @@ -1962,8 +1962,8 @@ public void testRoundDown() {

x = 4503599627370497.0; // x = Math.pow(2, 52) + 1;
assertEquals("4503599627370497", new BigDecimal(x).toString());
assertTrue(x == Math.rint(x));
assertTrue(x == AccurateMath.round(x));
assertEquals(x, Math.rint(x), 0.0);
assertEquals(x, AccurateMath.round(x), 0.0);
//assertTrue(x == Math.round(x)); // fails with Java 7, fixed in Java 8
}

Expand Down
Expand Up @@ -93,9 +93,9 @@ public void testSerialize()
ObjectInputStream ois = new ObjectInputStream(bis);
ExceptionContext cIn = (ExceptionContext) ois.readObject();

Assert.assertTrue(cOut.getMessage().equals(cIn.getMessage()));
Assert.assertEquals(cOut.getMessage(), cIn.getMessage());
for (String key : cIn.getKeys()) {
Assert.assertTrue(cOut.getValue(key).equals(cIn.getValue(key)));
Assert.assertEquals(cOut.getValue(key), cIn.getValue(key));
}
}

Expand Down
Expand Up @@ -1233,7 +1233,7 @@ public void testSignum() {

DerivativeStructure plusZero = new DerivativeStructure(1, 1, 0, +0.0);
Assert.assertEquals(+0.0, plusZero.signum().getPartialDerivative(0), 1.0e-15);
Assert.assertTrue(Double.doubleToLongBits(plusZero.signum().getValue()) == 0);
Assert.assertEquals(0, Double.doubleToLongBits(plusZero.signum().getValue()));
Assert.assertEquals( 0.0, plusZero.signum().getPartialDerivative(1), 1.0e-15);

}
Expand Down
Expand Up @@ -857,7 +857,7 @@ public void testSignum() {

SparseGradient plusZero = SparseGradient.createVariable(0, +0.0);
Assert.assertEquals(+0.0, plusZero.signum().getValue(), 1.0e-15);
Assert.assertTrue(Double.doubleToLongBits(plusZero.signum().getValue()) == 0);
Assert.assertEquals(0, Double.doubleToLongBits(plusZero.signum().getValue()));
Assert.assertEquals( 0.0, plusZero.signum().getDerivative(0), 1.0e-15);

}
Expand Down
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.commons.math4.legacy.analysis.polynomials;

import java.util.Arrays;

import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
Expand Down Expand Up @@ -62,7 +61,7 @@ public class PolynomialSplineFunctionTest {
public void testConstructor() {
PolynomialSplineFunction spline =
new PolynomialSplineFunction(knots, polynomials);
Assert.assertTrue(Arrays.equals(knots, spline.getKnots()));
Assert.assertArrayEquals(knots, spline.getKnots(), 0.0);
Assert.assertEquals(1d, spline.getPolynomials()[0].getCoefficients()[2], 0);
Assert.assertEquals(3, spline.getN());

Expand Down
Expand Up @@ -17,7 +17,6 @@
package org.apache.commons.math4.legacy.distribution.fitting;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.math4.legacy.distribution.MixtureMultivariateNormalDistribution;
Expand Down Expand Up @@ -182,7 +181,7 @@ public void testInitialMixture() {
Math.ulp(1d));

final double[] means = component.getValue().getMeans();
Assert.assertTrue(Arrays.equals(correctMeans[i], means));
Assert.assertArrayEquals(correctMeans[i], means, 0.0);

final RealMatrix covMat = component.getValue().getCovariances();
Assert.assertEquals(correctCovMats[i], covMat);
Expand Down Expand Up @@ -236,7 +235,7 @@ public void testFit() {
final double[] mean = mvn.getMeans();
final RealMatrix covMat = mvn.getCovariances();
Assert.assertEquals(correctWeights[i], weight, Math.ulp(1d));
Assert.assertTrue(Arrays.equals(correctMeans[i], mean));
Assert.assertArrayEquals(correctMeans[i], mean, 0.0);
Assert.assertEquals(correctCovMats[i], covMat);
i++;
}
Expand Down
Expand Up @@ -524,10 +524,10 @@ public void testEquals() {
T t1a = build(1.0);
T t1b = build(1.0);
T t2 = build(2.0);
Assert.assertTrue(t1a.equals(t1a));
Assert.assertTrue(t1a.equals(t1b));
Assert.assertFalse(t1a.equals(t2));
Assert.assertFalse(t1a.equals(new Object()));
Assert.assertEquals(t1a, t1a);
Assert.assertEquals(t1a, t1b);
Assert.assertNotEquals(t1a, t2);
Assert.assertNotEquals(t1a, new Object());
}

@Test
Expand Down
Expand Up @@ -87,11 +87,11 @@ public void testToListCopy() {
store.add(new WeightedObservedPoint(2, -3, -4));

final List<WeightedObservedPoint> list = store.toList();
Assert.assertTrue(list.size() == 2);
Assert.assertEquals(2, list.size());

// Adding an element to "list" has no impact on "store".
list.add(new WeightedObservedPoint(1.2, 3.4, 5.6));
Assert.assertFalse(list.size() == store.toList().size());
Assert.assertNotEquals(list.size(), store.toList().size());

// Clearing "store" has no impact on "list".
store.clear();
Expand Down
Expand Up @@ -36,13 +36,13 @@ public void testConverged() {

//action + verify
//just matches rel tol
Assert.assertEquals(true, checker.converged(0, e200, mockEvaluation(210)));
Assert.assertTrue(checker.converged(0, e200, mockEvaluation(210)));
//just matches abs tol
Assert.assertEquals(true, checker.converged(0, e1, mockEvaluation(1.9)));
Assert.assertTrue(checker.converged(0, e1, mockEvaluation(1.9)));
//matches both
Assert.assertEquals(true, checker.converged(0, e1, mockEvaluation(1.01)));
Assert.assertTrue(checker.converged(0, e1, mockEvaluation(1.01)));
//matches neither
Assert.assertEquals(false, checker.converged(0, e200, mockEvaluation(300)));
Assert.assertFalse(checker.converged(0, e200, mockEvaluation(300)));
}

/**
Expand Down
Expand Up @@ -106,7 +106,7 @@ public void testDimensions() {
Assert.assertTrue("testData is square",m.isSquare());
Assert.assertEquals("testData2 row dimension",m2.getRowDimension(),2);
Assert.assertEquals("testData2 column dimension",m2.getColumnDimension(),3);
Assert.assertTrue("testData2 is not square",!m2.isSquare());
Assert.assertFalse("testData2 is not square", m2.isSquare());
}

/** test copy functions */
Expand Down Expand Up @@ -895,9 +895,9 @@ public void testEqualsAndHashCode() {
Assert.assertEquals(m.hashCode(), m1.hashCode());
Assert.assertEquals(m, m);
Assert.assertEquals(m, m1);
Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(new Array2DRowRealMatrix(bigSingular)));
Assert.assertNotEquals(null, m);
Assert.assertNotEquals(m, mt);
Assert.assertNotEquals(m, new Array2DRowRealMatrix(bigSingular));
}

@Test
Expand Down
Expand Up @@ -152,9 +152,9 @@ public void testSingularMatrix() {
Assert.assertEquals(0, v.subtract(vRef).getNorm(), 1.0e-14);

// check the same cached instance is returned the second time
Assert.assertTrue(u == transformer.getU());
Assert.assertTrue(b == transformer.getB());
Assert.assertTrue(v == transformer.getV());
Assert.assertSame(u, transformer.getU());
Assert.assertSame(b, transformer.getB());
Assert.assertSame(v, transformer.getV());

}

Expand Down Expand Up @@ -185,9 +185,9 @@ public void testMatricesValues() {
Assert.assertEquals(0, v.subtract(vRef).getNorm(), 1.0e-14);

// check the same cached instance is returned the second time
Assert.assertTrue(u == transformer.getU());
Assert.assertTrue(b == transformer.getB());
Assert.assertTrue(v == transformer.getV());
Assert.assertSame(u, transformer.getU());
Assert.assertSame(b, transformer.getB());
Assert.assertSame(v, transformer.getV());

}

Expand Down
Expand Up @@ -37,7 +37,7 @@ public void testOne() {
public void testSerial() {
// deserializing the singleton should give the singleton itself back
BigRealField field = BigRealField.getInstance();
Assert.assertTrue(field == TestUtils.serializeAndRecover(field));
Assert.assertSame(field, TestUtils.serializeAndRecover(field));
}

}
Expand Up @@ -166,15 +166,15 @@ public void testBigDecimalValue() {
public void testEqualsAndHashCode() {
BigReal zero = new BigReal(0.0);
BigReal nullReal = null;
Assert.assertTrue(zero.equals(zero));
Assert.assertFalse(zero.equals(nullReal));
Assert.assertEquals(zero, zero);
Assert.assertNotEquals(zero, nullReal);
Assert.assertFalse(zero.equals(Double.valueOf(0)));
BigReal zero2 = new BigReal(0.0);
Assert.assertTrue(zero.equals(zero2));
Assert.assertEquals(zero, zero2);
Assert.assertEquals(zero.hashCode(), zero2.hashCode());
BigReal one = new BigReal(1.0);
Assert.assertFalse(one.equals(zero) || zero.equals(one));
Assert.assertTrue(one.equals(BigReal.ONE));
Assert.assertEquals(one, BigReal.ONE);
BigReal oneWithScaleOne = new BigReal(new BigDecimal("1.0"));
BigReal oneWithScaleTwo = new BigReal(new BigDecimal("1.00"));
Assert.assertEquals(oneWithScaleOne, oneWithScaleTwo);
Expand Down
Expand Up @@ -164,7 +164,7 @@ public void testDimensions() {
Assert.assertTrue("testData is square",m.isSquare());
Assert.assertEquals("testData2 row dimension",m2.getRowDimension(),2);
Assert.assertEquals("testData2 column dimension",m2.getColumnDimension(),3);
Assert.assertTrue("testData2 is not square",!m2.isSquare());
Assert.assertFalse("testData2 is not square", m2.isSquare());
}

/** test copy functions */
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public void testGetRow() {
@Test
public void testSetRow() {
FieldMatrix<Dfp> m = new BlockFieldMatrix<>(subTestData);
Assert.assertTrue(subRow3[0][0] != m.getRow(0)[0]);
Assert.assertNotSame(subRow3[0][0], m.getRow(0)[0]);
m.setRow(0, subRow3[0]);
checkArrays(subRow3[0], m.getRow(0));
try {
Expand Down Expand Up @@ -1088,7 +1088,7 @@ public void testGetColumn() {
public void testSetColumn() {
FieldMatrix<Dfp> m = new BlockFieldMatrix<>(subTestData);
Dfp[] mColumn3 = columnToArray(subColumn3);
Assert.assertTrue(mColumn3[0] != m.getColumn(1)[0]);
Assert.assertNotSame(mColumn3[0], m.getColumn(1)[0]);
m.setColumn(1, mColumn3);
checkArrays(mColumn3, m.getColumn(1));
try {
Expand Down Expand Up @@ -1150,9 +1150,9 @@ public void testEqualsAndHashCode() {
Assert.assertEquals(m.hashCode(), m1.hashCode());
Assert.assertEquals(m, m);
Assert.assertEquals(m, m1);
Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(new BlockFieldMatrix<>(bigSingular)));
Assert.assertNotEquals(null, m);
Assert.assertNotEquals(m, mt);
Assert.assertNotEquals(m, new BlockFieldMatrix<>(bigSingular));
}

@Test
Expand Down
Expand Up @@ -106,7 +106,7 @@ public void testDimensions() {
Assert.assertTrue("testData is square",m.isSquare());
Assert.assertEquals("testData2 row dimension",m2.getRowDimension(),2);
Assert.assertEquals("testData2 column dimension",m2.getColumnDimension(),3);
Assert.assertTrue("testData2 is not square",!m2.isSquare());
Assert.assertFalse("testData2 is not square", m2.isSquare());
}

/** test copy functions */
Expand Down Expand Up @@ -1054,9 +1054,9 @@ public void testEqualsAndHashCode() {
Assert.assertEquals(m.hashCode(), m1.hashCode());
Assert.assertEquals(m, m);
Assert.assertEquals(m, m1);
Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(new BlockRealMatrix(bigSingular)));
Assert.assertNotEquals(null, m);
Assert.assertNotEquals(m, mt);
Assert.assertNotEquals(m, new BlockRealMatrix(bigSingular));
}

@Test
Expand Down
Expand Up @@ -132,7 +132,7 @@ public void testMatricesValues() {
Assert.assertEquals(0, lt.subtract(lRef.transpose()).getNorm(), 1.0e-13);

// check the same cached instance is returned the second time
Assert.assertTrue(l == llt.getL());
Assert.assertTrue(lt == llt.getLT());
Assert.assertSame(l, llt.getL());
Assert.assertSame(lt, llt.getLT());
}
}
Expand Up @@ -53,7 +53,7 @@ public void testConstructor2() {

// Check that the underlying was copied.
d[0] = 0;
Assert.assertFalse(d[0] == m.getEntry(0, 0));
Assert.assertNotEquals(d[0], m.getEntry(0, 0), 0.0);
}

@Test
Expand All @@ -72,7 +72,7 @@ public void testConstructor3() {

// Check that the underlying is referenced.
d[0] = 0;
Assert.assertTrue(d[0] == m.getEntry(0, 0));
Assert.assertEquals(d[0], m.getEntry(0, 0), 0.0);

}

Expand Down

0 comments on commit 2509ce8

Please sign in to comment.