From 15b2e503281028b3131b6fd8f28c73128a59751e Mon Sep 17 00:00:00 2001 From: John Patrick <142304+nhojpatrick@users.noreply.github.com> Date: Fri, 21 Oct 2022 09:13:37 +0100 Subject: [PATCH] JUnit5 assertThrows MapRankingTest (#215) --- .../commons/math4/neuralnet/MapRankingTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/MapRankingTest.java b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/MapRankingTest.java index fb31a3c3f..6d1f9f4ad 100644 --- a/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/MapRankingTest.java +++ b/commons-math-neuralnet/src/test/java/org/apache/commons/math4/neuralnet/MapRankingTest.java @@ -29,10 +29,13 @@ import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.neuralnet.oned.NeuronString; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * Tests for {@link MapRanking} class. */ public class MapRankingTest { + /* * Test assumes that the network is * @@ -94,15 +97,20 @@ public class MapRankingTest { Assert.assertEquals(3, allBest.size()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRankPrecondition() { final UniformRandomProvider rng = RandomSource.SPLIT_MIX_64.create(); final FeatureInitializer init = new OffsetFeatureInitializer(FeatureInitializerFactory.uniform(rng, -0.1, 0.1)); final FeatureInitializer[] initArray = {init}; - new MapRanking(new NeuronString(3, false, initArray).getNetwork(), - new EuclideanDistance()).rank(new double[] {-1}, 0); + final EuclideanDistance distance = new EuclideanDistance(); + final Network network = new NeuronString(3, false, initArray).getNetwork(); + final MapRanking mapRanking = new MapRanking(network, distance); + + assertThrows(IllegalArgumentException.class, () -> + mapRanking.rank(new double[]{-1}, 0) + ); } @Test @@ -121,4 +129,5 @@ public class MapRankingTest { Assert.assertEquals(expected[i], sorted.get(i).getIdentifier()); } } + }