diff options
Diffstat (limited to 'store/src/test/java/tools/refinery/data/map/tests/fuzz/MutableFuzzTest.java')
-rw-r--r-- | store/src/test/java/tools/refinery/data/map/tests/fuzz/MutableFuzzTest.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/store/src/test/java/tools/refinery/data/map/tests/fuzz/MutableFuzzTest.java b/store/src/test/java/tools/refinery/data/map/tests/fuzz/MutableFuzzTest.java new file mode 100644 index 00000000..a16cb8f5 --- /dev/null +++ b/store/src/test/java/tools/refinery/data/map/tests/fuzz/MutableFuzzTest.java | |||
@@ -0,0 +1,92 @@ | |||
1 | package tools.refinery.data.map.tests.fuzz; | ||
2 | |||
3 | import static org.junit.jupiter.api.Assertions.fail; | ||
4 | |||
5 | import java.util.Random; | ||
6 | import java.util.stream.Stream; | ||
7 | |||
8 | import org.junit.jupiter.api.Tag; | ||
9 | import org.junit.jupiter.api.Timeout; | ||
10 | import org.junit.jupiter.params.ParameterizedTest; | ||
11 | import org.junit.jupiter.params.provider.Arguments; | ||
12 | import org.junit.jupiter.params.provider.MethodSource; | ||
13 | |||
14 | import tools.refinery.data.map.ContinousHashProvider; | ||
15 | import tools.refinery.data.map.VersionedMapStore; | ||
16 | import tools.refinery.data.map.VersionedMapStoreImpl; | ||
17 | import tools.refinery.data.map.internal.VersionedMapImpl; | ||
18 | import tools.refinery.data.map.tests.fuzz.utils.FuzzTestUtils; | ||
19 | import tools.refinery.data.map.tests.utils.MapTestEnvironment; | ||
20 | |||
21 | class MutableFuzzTest { | ||
22 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, boolean evilHash) { | ||
23 | String[] values = MapTestEnvironment.prepareValues(maxValue); | ||
24 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | ||
25 | |||
26 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | ||
27 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); | ||
28 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<Integer, String>(sut); | ||
29 | |||
30 | Random r = new Random(seed); | ||
31 | |||
32 | iterativeRandomPuts(scenario, steps, maxKey, values, e, r); | ||
33 | } | ||
34 | |||
35 | private void iterativeRandomPuts(String scenario, int steps, int maxKey, String[] values, | ||
36 | MapTestEnvironment<Integer, String> e, Random r) { | ||
37 | int stopAt = -1; | ||
38 | for (int i = 0; i < steps; i++) { | ||
39 | int index = i + 1; | ||
40 | int nextKey = r.nextInt(maxKey); | ||
41 | String nextValue = values[r.nextInt(values.length)]; | ||
42 | if (index == stopAt) { | ||
43 | System.out.println("issue!"); | ||
44 | System.out.println("State before:"); | ||
45 | e.printComparison(); | ||
46 | e.sut.prettyPrint(); | ||
47 | System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); | ||
48 | } | ||
49 | try { | ||
50 | e.put(nextKey, nextValue); | ||
51 | if (index == stopAt) { | ||
52 | e.sut.prettyPrint(); | ||
53 | } | ||
54 | e.checkEquivalence(scenario + ":" + index); | ||
55 | } catch (Exception exception) { | ||
56 | exception.printStackTrace(); | ||
57 | fail(scenario + ":" + index + ": exception happened: " + exception); | ||
58 | } | ||
59 | MapTestEnvironment.printStatus(scenario, index, steps, null); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | @ParameterizedTest(name = "Mutable {index}/{0} Steps={1} Keys={2} Values={3} seed={4} evil-hash={5}") | ||
64 | @MethodSource | ||
65 | @Timeout(value = 10) | ||
66 | @Tag("fuzz") | ||
67 | void parametrizedFuzz(int test, int steps, int noKeys, int noValues, int seed, boolean evilHash) { | ||
68 | runFuzzTest( | ||
69 | "MutableS" + steps + "K" + noKeys + "V" + noValues + "s" + seed + "H" + (evilHash ? "Evil" : "Normal"), | ||
70 | seed, steps, noKeys, noValues, evilHash); | ||
71 | } | ||
72 | |||
73 | static Stream<Arguments> parametrizedFuzz() { | ||
74 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, | ||
75 | new Object[] { 3, 32, 32 * 32, 32 * 32 * 32 * 32 }, new Object[] { 2, 3 }, new Object[] { 1, 2, 3 }, | ||
76 | new Object[] { false, true }); | ||
77 | } | ||
78 | |||
79 | @ParameterizedTest(name = "Mutable {index}/{0} Steps={1} Keys={2} Values={3} seed={4} evil-hash={5}") | ||
80 | @MethodSource | ||
81 | @Tag("fuzz") | ||
82 | @Tag("slow") | ||
83 | void parametrizedSlowFuzz(int test, int steps, int noKeys, int noValues, int seed, boolean evilHash) { | ||
84 | runFuzzTest( | ||
85 | "MutableS" + steps + "K" + noKeys + "V" + noValues + "s" + seed + "H" + (evilHash ? "Evil" : "Normal"), | ||
86 | seed, steps, noKeys, noValues, evilHash); | ||
87 | } | ||
88 | |||
89 | static Stream<Arguments> parametrizedSlowFuzz() { | ||
90 | return FuzzTestUtils.changeStepCount(parametrizedFuzz(), 1); | ||
91 | } | ||
92 | } | ||