JUnit5 assertThrows MapRankingTest (#215)

This commit is contained in:
John Patrick 2022-10-21 09:13:37 +01:00 committed by GitHub
parent 5e497dd704
commit 15b2e50328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -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());
}
}
}