Replace calls to deprecated classes and methods (unit tests).

This commit is contained in:
Gilles Sadowski 2022-01-18 04:37:54 +01:00
parent d81b5e921e
commit ae6ceeadd1
3 changed files with 6 additions and 16 deletions

View File

@ -39,10 +39,6 @@ import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.sameInstance;
/** /**
* Some of the unit tests are re-implementations of the MINPACK <a * Some of the unit tests are re-implementations of the MINPACK <a
* href="http://www.netlib.org/minpack/ex/file17">file17</a> and <a * href="http://www.netlib.org/minpack/ex/file17">file17</a> and <a
@ -549,9 +545,7 @@ public abstract class AbstractLeastSquaresOptimizerAbstractTest {
.checker(new ConvergenceChecker<Evaluation>() { .checker(new ConvergenceChecker<Evaluation>() {
@Override @Override
public boolean converged(int iteration, Evaluation previous, Evaluation current) { public boolean converged(int iteration, Evaluation previous, Evaluation current) {
Assert.assertThat( Assert.assertFalse(previous.getPoint().equals(current.getPoint()));
previous.getPoint(),
not(sameInstance(current.getPoint())));
Assert.assertArrayEquals(new double[3], previous.getPoint().toArray(), 0); Assert.assertArrayEquals(new double[3], previous.getPoint().toArray(), 0);
Assert.assertArrayEquals(new double[] {1, 2, 3}, current.getPoint().toArray(), TOL); Assert.assertArrayEquals(new double[] {1, 2, 3}, current.getPoint().toArray(), TOL);
checked[0] = true; checked[0] = true;
@ -560,7 +554,7 @@ public abstract class AbstractLeastSquaresOptimizerAbstractTest {
}); });
optimizer.optimize(builder.build()); optimizer.optimize(builder.build());
Assert.assertThat(checked[0], is(true)); Assert.assertTrue(checked[0]);
} }
class LinearProblem { class LinearProblem {

View File

@ -32,8 +32,6 @@ import org.apache.commons.numbers.core.Precision;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
/** /**
* <p>Some of the unit tests are re-implementations of the MINPACK <a * <p>Some of the unit tests are re-implementations of the MINPACK <a
* href="http://www.netlib.org/minpack/ex/file17">file17</a> and <a * href="http://www.netlib.org/minpack/ex/file17">file17</a> and <a
@ -339,8 +337,7 @@ public class LevenbergMarquardtOptimizerTest
//verify //verify
//check iterations and evaluations are not switched. //check iterations and evaluations are not switched.
Assert.assertThat(optimum.getIterations(), is(1)); Assert.assertEquals(1, optimum.getIterations());
Assert.assertThat(optimum.getEvaluations(), is(2)); Assert.assertEquals(2, optimum.getEvaluations());
} }
} }

View File

@ -26,7 +26,6 @@ import org.apache.commons.math4.legacy.ml.distance.CanberraDistance;
import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure;
import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.UniformRandomProvider;
import org.hamcrest.CoreMatchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -101,8 +100,8 @@ public class FuzzyKMeansClustererTest {
Assert.assertEquals(2.0, clusterer.getFuzziness(), 1e-6); Assert.assertEquals(2.0, clusterer.getFuzziness(), 1e-6);
Assert.assertEquals(100, clusterer.getMaxIterations()); Assert.assertEquals(100, clusterer.getMaxIterations());
Assert.assertEquals(1e-6, clusterer.getEpsilon(), 1e-12); Assert.assertEquals(1e-6, clusterer.getEpsilon(), 1e-12);
Assert.assertThat(clusterer.getDistanceMeasure(), CoreMatchers.is(measure)); Assert.assertEquals(measure, clusterer.getDistanceMeasure());
Assert.assertThat(clusterer.getRandomGenerator(), CoreMatchers.is(random)); Assert.assertEquals(random, clusterer.getRandomGenerator());
} }
@Test @Test