diff --git a/src/main/java/be/cylab/java/wowa/training/Factory.java b/src/main/java/be/cylab/java/wowa/training/Factory.java index 31877dada0e42369ca42936ec94a8149b34d2efc..40073df29067309cda229ee90212709109ccb871 100644 --- a/src/main/java/be/cylab/java/wowa/training/Factory.java +++ b/src/main/java/be/cylab/java/wowa/training/Factory.java @@ -24,7 +24,7 @@ public class Factory { return new SolutionAUC(a); } else { throw new IllegalArgumentException( - "Provide o correct type of Solution"); + "Provide a correct type of Solution"); } } } diff --git a/src/test/java/be/cylab/java/wowa/training/UtilsTest.java b/src/test/java/be/cylab/java/wowa/training/UtilsTest.java index 2c0d23e06d17b4523ec49b138fd6230a23f6310d..e389ff7f75ef898c218543684ef1428c4388d936 100644 --- a/src/test/java/be/cylab/java/wowa/training/UtilsTest.java +++ b/src/test/java/be/cylab/java/wowa/training/UtilsTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; +import java.util.Random; import static org.junit.jupiter.api.Assertions.*; @@ -20,7 +21,7 @@ class UtilsTest { } @Test - void sumListElements() { + void testSumListElements() { List<Double> weights = new ArrayList<>(); weights.add(0.365); weights.add(0.658); @@ -39,7 +40,7 @@ class UtilsTest { } @Test - void normalizeWeights() { + void testNormalizeWeights() { List<Double> weights = new ArrayList<>(); weights.add(0.365); weights.add(0.658); @@ -74,19 +75,49 @@ class UtilsTest { } @Test - void findMaxDistance() { + void testFindMinDistance() { + List<AbstractSolution> population = new ArrayList<>(); + Random rnd = new Random(5478); + List<List<Double>> data = Utils.convertJsonToDataForTrainer("./ressources/webshell_data.json"); + List<Double> expected = Utils.convertJsonToExpectedForTrainer("./ressources/webshell_expected.json"); + for (int i = 0; i < 50; i++) { + SolutionDistance solution = new SolutionDistance(5,rnd.nextInt()); + solution.computeScoreTo(data, expected); + population.add(solution); + } + assertEquals(8.668597844797882, Utils.findMinDistance(population)); } @Test - void findMinDistance() { + void testFindMaxDistance() { + List<AbstractSolution> population = new ArrayList<>(); + Random rnd = new Random(5478); + List<List<Double>> data = Utils.convertJsonToDataForTrainer("./ressources/webshell_data.json"); + List<Double> expected = Utils.convertJsonToExpectedForTrainer("./ressources/webshell_expected.json"); + for (int i = 0; i < 50; i++) { + SolutionDistance solution = new SolutionDistance(5,rnd.nextInt()); + solution.computeScoreTo(data, expected); + population.add(solution); + } + assertEquals(34.18904600152107, Utils.findMaxDistance(population)); } @Test - void sumTotalDistance() { + void testSumTotalDistance() { + List<AbstractSolution> population = new ArrayList<>(); + Random rnd = new Random(5478); + List<List<Double>> data = Utils.convertJsonToDataForTrainer("./ressources/webshell_data.json"); + List<Double> expected = Utils.convertJsonToExpectedForTrainer("./ressources/webshell_expected.json"); + for (int i = 0; i < 50; i++) { + SolutionDistance solution = new SolutionDistance(5,rnd.nextInt()); + solution.computeScoreTo(data, expected); + population.add(solution); + } + assertEquals(781.5916287000892, Utils.sumTotalDistance(population)); } @Test - void randomInteger() { + void testRandomInteger() { int a = Utils.randomInteger(0, 500); assertTrue(a > 0); assertTrue(a < 500); @@ -98,18 +129,18 @@ class UtilsTest { } @Test - void computeWOWAScoreWithData() { + void testComputeWOWAScoreWithData() { } @Test - void convertExpectedToBooleanArrayTrueAlert() { + void testConvertExpectedToBooleanArrayTrueAlert() { } @Test - void convertListDoubleToArrayDouble() { + void testConvertListDoubleToArrayDouble() { } @Test - void initializeListWithZeroValues() { + void testInitializeListWithZeroValues() { } } \ No newline at end of file