diff options
Diffstat (limited to 'subprojects/store-dse/src/test/java/tools')
-rw-r--r-- | subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/statespace/internal/ActivationUnitTest.java | 101 |
1 files changed, 80 insertions, 21 deletions
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/statespace/internal/ActivationUnitTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/statespace/internal/ActivationUnitTest.java index e7960a06..3a672b18 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/statespace/internal/ActivationUnitTest.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/statespace/internal/ActivationUnitTest.java | |||
@@ -9,6 +9,11 @@ import org.junit.jupiter.api.Assertions; | |||
9 | import org.junit.jupiter.params.ParameterizedTest; | 9 | import org.junit.jupiter.params.ParameterizedTest; |
10 | import org.junit.jupiter.params.provider.MethodSource; | 10 | import org.junit.jupiter.params.provider.MethodSource; |
11 | 11 | ||
12 | import java.util.ArrayList; | ||
13 | import java.util.Collections; | ||
14 | import java.util.List; | ||
15 | import java.util.Random; | ||
16 | import java.util.function.Supplier; | ||
12 | import java.util.stream.Stream; | 17 | import java.util.stream.Stream; |
13 | 18 | ||
14 | class ActivationUnitTest { | 19 | class ActivationUnitTest { |
@@ -17,56 +22,110 @@ class ActivationUnitTest { | |||
17 | private static Stream<ActivationStoreEntry> entries() { | 22 | private static Stream<ActivationStoreEntry> entries() { |
18 | return Stream.of( | 23 | return Stream.of( |
19 | new ActivationStoreBitVectorEntry(SMALL_SIZE), | 24 | new ActivationStoreBitVectorEntry(SMALL_SIZE), |
20 | new ActivationStoreListEntry(SMALL_SIZE)); | 25 | new ActivationStoreListEntry(SMALL_SIZE) |
26 | ); | ||
21 | } | 27 | } |
22 | 28 | ||
23 | void addTest(ActivationStoreEntry entry, int elementsAdded) { | 29 | void addTest(ActivationStoreEntry entry, int elementsAdded) { |
24 | Assertions.assertEquals(elementsAdded,entry.getNumberOfVisitedActivations()); | 30 | Assertions.assertEquals(elementsAdded, entry.getNumberOfVisitedActivations()); |
25 | Assertions.assertEquals(SMALL_SIZE-elementsAdded,entry.getNumberOfUnvisitedActivations()); | 31 | Assertions.assertEquals(SMALL_SIZE - elementsAdded, entry.getNumberOfUnvisitedActivations()); |
26 | } | 32 | } |
27 | 33 | ||
28 | @ParameterizedTest | 34 | @ParameterizedTest |
29 | @MethodSource("entries") | 35 | @MethodSource("entries") |
30 | void testDifferent(ActivationStoreEntry entry) { | 36 | void testDifferent(ActivationStoreEntry entry) { |
31 | int elementsAdded = 0; | 37 | int elementsAdded = 0; |
32 | addTest(entry,elementsAdded); | 38 | addTest(entry, elementsAdded); |
33 | Assertions.assertEquals(2, entry.getAndAddActivationAfter(2)); | 39 | Assertions.assertEquals(2, entry.getAndAddActivationAfter(2)); |
34 | addTest(entry,++elementsAdded); | 40 | addTest(entry, ++elementsAdded); |
35 | Assertions.assertEquals(3,entry.getAndAddActivationAfter(3)); | 41 | Assertions.assertEquals(3, entry.getAndAddActivationAfter(3)); |
36 | addTest(entry,++elementsAdded); | 42 | addTest(entry, ++elementsAdded); |
37 | Assertions.assertEquals(1,entry.getAndAddActivationAfter(1)); | 43 | Assertions.assertEquals(1, entry.getAndAddActivationAfter(1)); |
38 | addTest(entry,++elementsAdded); | 44 | addTest(entry, ++elementsAdded); |
39 | Assertions.assertEquals(4,entry.getAndAddActivationAfter(4)); | 45 | Assertions.assertEquals(4, entry.getAndAddActivationAfter(4)); |
40 | addTest(entry,++elementsAdded); | 46 | addTest(entry, ++elementsAdded); |
41 | Assertions.assertEquals(0,entry.getAndAddActivationAfter(0)); | 47 | Assertions.assertEquals(0, entry.getAndAddActivationAfter(0)); |
42 | addTest(entry,++elementsAdded); | 48 | addTest(entry, ++elementsAdded); |
43 | } | 49 | } |
44 | 50 | ||
51 | |||
45 | @ParameterizedTest | 52 | @ParameterizedTest |
46 | @MethodSource("entries") | 53 | @MethodSource("entries") |
47 | void testSame(ActivationStoreEntry entry) { | 54 | void testSame(ActivationStoreEntry entry) { |
48 | int elementsAdded = 0; | 55 | int elementsAdded = 0; |
49 | addTest(entry,elementsAdded); | 56 | addTest(entry, 0); |
50 | entry.getAndAddActivationAfter(2); | 57 | entry.getAndAddActivationAfter(2); |
51 | addTest(entry,++elementsAdded); | 58 | addTest(entry, ++elementsAdded); |
52 | entry.getAndAddActivationAfter(2); | 59 | entry.getAndAddActivationAfter(2); |
53 | addTest(entry,++elementsAdded); | 60 | addTest(entry, ++elementsAdded); |
54 | entry.getAndAddActivationAfter(2); | 61 | entry.getAndAddActivationAfter(2); |
55 | addTest(entry,++elementsAdded); | 62 | addTest(entry, ++elementsAdded); |
56 | entry.getAndAddActivationAfter(2); | 63 | entry.getAndAddActivationAfter(2); |
57 | addTest(entry,++elementsAdded); | 64 | addTest(entry, ++elementsAdded); |
58 | entry.getAndAddActivationAfter(2); | 65 | entry.getAndAddActivationAfter(2); |
59 | addTest(entry,++elementsAdded); | 66 | addTest(entry, ++elementsAdded); |
60 | } | 67 | } |
61 | 68 | ||
62 | @ParameterizedTest | 69 | @ParameterizedTest |
63 | @MethodSource("entries") | 70 | @MethodSource("entries") |
64 | void testFilling(ActivationStoreEntry entry) { | 71 | void testFilling(ActivationStoreEntry entry) { |
65 | int elementsAdded = 0; | 72 | int elementsAdded = 0; |
66 | while(elementsAdded < SMALL_SIZE) { | 73 | while (elementsAdded < SMALL_SIZE) { |
67 | entry.getAndAddActivationAfter(2); | 74 | entry.getAndAddActivationAfter(2); |
68 | elementsAdded++; | 75 | elementsAdded++; |
69 | } | 76 | } |
70 | Assertions.assertThrows(IllegalArgumentException.class,()-> entry.getAndAddActivationAfter(2)); | 77 | Assertions.assertThrows(IllegalArgumentException.class, () -> entry.getAndAddActivationAfter(2)); |
78 | } | ||
79 | |||
80 | void randomDifferentTestCase(ActivationStoreEntry entry, int seed) { | ||
81 | List<Integer> elements = new ArrayList<>(SMALL_SIZE); | ||
82 | for (int i = 0; i < SMALL_SIZE; i++) { | ||
83 | elements.add(i); | ||
84 | } | ||
85 | @SuppressWarnings("squid:S2245") | ||
86 | var random = new Random(seed); | ||
87 | Collections.shuffle(elements, random); | ||
88 | |||
89 | for (int element : elements) { | ||
90 | entry.getAndAddActivationAfter(element); | ||
91 | } | ||
92 | Assertions.assertThrows(IllegalArgumentException.class, () -> entry.getAndAddActivationAfter(2)); | ||
93 | } | ||
94 | |||
95 | private static final int fuzzNumber = 20; | ||
96 | |||
97 | @ParameterizedTest | ||
98 | @MethodSource("entryFactories") | ||
99 | void randomDifferentTest(Supplier<ActivationStoreEntry> entry) { | ||
100 | for (int i = 0; i < fuzzNumber; i++) { | ||
101 | randomDifferentTestCase(entry.get(), i); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void randomSameTestCase(ActivationStoreEntry entry, int seed) { | ||
106 | |||
107 | @SuppressWarnings("squid:S2245") | ||
108 | var random = new Random(seed); | ||
109 | |||
110 | for (int i = 0; i < SMALL_SIZE; i++) { | ||
111 | entry.getAndAddActivationAfter(random.nextInt(SMALL_SIZE)); | ||
112 | } | ||
113 | |||
114 | Assertions.assertThrows(IllegalArgumentException.class, () -> entry.getAndAddActivationAfter(2)); | ||
115 | } | ||
116 | |||
117 | @ParameterizedTest | ||
118 | @MethodSource("entryFactories") | ||
119 | void randomSameTest(Supplier<ActivationStoreEntry> entry) { | ||
120 | for (int i = 0; i < fuzzNumber; i++) { | ||
121 | randomSameTestCase(entry.get(), i); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | private static Stream<Supplier<ActivationStoreEntry>> entryFactories() { | ||
126 | return Stream.of( | ||
127 | () -> new ActivationStoreBitVectorEntry(SMALL_SIZE), | ||
128 | () -> new ActivationStoreListEntry(SMALL_SIZE) | ||
129 | ); | ||
71 | } | 130 | } |
72 | } | 131 | } |