From b9ca8352a838cc93dd69f8b096fb989e0801a425 Mon Sep 17 00:00:00 2001 From: Alex <croix.alexandre@gmail.com> Date: Thu, 8 Aug 2019 11:18:15 +0200 Subject: [PATCH] Improve tests --- .../be/cylab/java/wowa/training/Factory.java | 2 +- .../cylab/java/wowa/training/UtilsTest.java | 51 +++++++++++++++---- 2 files changed, 42 insertions(+), 11 deletions(-) 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 31877da..40073df 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 2c0d23e..e389ff7 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 -- GitLab