diff options
author | 2023-02-05 20:27:45 +0100 | |
---|---|---|
committer | 2023-02-05 20:27:45 +0100 | |
commit | 01d06bb9d04894029d2be304f6d4dccb757ea9dc (patch) | |
tree | 32aa12eba51859c86898e0eac6aaf03d9a504956 | |
parent | Merge remote-tracking branch 'origin/datastructure' into datastructure (diff) | |
download | refinery-01d06bb9d04894029d2be304f6d4dccb757ea9dc.tar.gz refinery-01d06bb9d04894029d2be304f6d4dccb757ea9dc.tar.zst refinery-01d06bb9d04894029d2be304f6d4dccb757ea9dc.zip |
Formatting fuzz tests + improving code qualitz
12 files changed, 107 insertions, 129 deletions
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/CommitFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/CommitFuzzTest.java index c872b9da..cd32337e 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/CommitFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/CommitFuzzTest.java | |||
@@ -22,12 +22,12 @@ class CommitFuzzTest { | |||
22 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 22 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
23 | boolean nullDefault, int commitFrequency, | 23 | boolean nullDefault, int commitFrequency, |
24 | boolean evilHash) { | 24 | boolean evilHash) { |
25 | String[] values = MapTestEnvironment.prepareValues(maxValue,nullDefault); | 25 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
26 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 26 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
27 | 27 | ||
28 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 28 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); |
29 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); | 29 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); |
30 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<Integer, String>(sut); | 30 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<>(sut); |
31 | 31 | ||
32 | Random r = new Random(seed); | 32 | Random r = new Random(seed); |
33 | 33 | ||
@@ -35,24 +35,13 @@ class CommitFuzzTest { | |||
35 | } | 35 | } |
36 | 36 | ||
37 | private void iterativeRandomPutsAndCommits(String scenario, int steps, int maxKey, String[] values, | 37 | private void iterativeRandomPutsAndCommits(String scenario, int steps, int maxKey, String[] values, |
38 | MapTestEnvironment<Integer, String> e, Random r, int commitFrequency) { | 38 | MapTestEnvironment<Integer, String> e, Random r, int commitFrequency) { |
39 | int stopAt = -1; | ||
40 | for (int i = 0; i < steps; i++) { | 39 | for (int i = 0; i < steps; i++) { |
41 | int index = i + 1; | 40 | int index = i + 1; |
42 | int nextKey = r.nextInt(maxKey); | 41 | int nextKey = r.nextInt(maxKey); |
43 | String nextValue = values[r.nextInt(values.length)]; | 42 | String nextValue = values[r.nextInt(values.length)]; |
44 | if (index == stopAt) { | ||
45 | System.out.println("issue!"); | ||
46 | System.out.println("State before:"); | ||
47 | e.printComparison(); | ||
48 | e.sut.prettyPrint(); | ||
49 | System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); | ||
50 | } | ||
51 | try { | 43 | try { |
52 | e.put(nextKey, nextValue); | 44 | e.put(nextKey, nextValue); |
53 | if (index == stopAt) { | ||
54 | e.sut.prettyPrint(); | ||
55 | } | ||
56 | e.checkEquivalence(scenario + ":" + index); | 45 | e.checkEquivalence(scenario + ":" + index); |
57 | } catch (Exception exception) { | 46 | } catch (Exception exception) { |
58 | exception.printStackTrace(); | 47 | exception.printStackTrace(); |
@@ -78,9 +67,9 @@ class CommitFuzzTest { | |||
78 | } | 67 | } |
79 | 68 | ||
80 | static Stream<Arguments> parametrizedFastFuzz() { | 69 | static Stream<Arguments> parametrizedFastFuzz() { |
81 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, | 70 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, 32 * 32}, |
82 | new Object[] { 2, 3 }, new Object[]{false,true}, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | 71 | new Object[]{2, 3}, new Object[]{false, true}, new Object[]{1, 10, 100}, new Object[]{1, 2, 3}, |
83 | new Object[] { false, true }); | 72 | new Object[]{false, true}); |
84 | } | 73 | } |
85 | 74 | ||
86 | @ParameterizedTest(name = "Commit {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} commit frequency={5} " + | 75 | @ParameterizedTest(name = "Commit {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} commit frequency={5} " + |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/ContentEqualsFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/ContentEqualsFuzzTest.java index a5a68b94..996bfa03 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/ContentEqualsFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/ContentEqualsFuzzTest.java | |||
@@ -34,7 +34,7 @@ class ContentEqualsFuzzTest { | |||
34 | private void iterativeRandomPutsAndCommitsThenCompare(String scenario, ContinousHashProvider<Integer> chp, | 34 | private void iterativeRandomPutsAndCommitsThenCompare(String scenario, ContinousHashProvider<Integer> chp, |
35 | int steps, int maxKey, String[] values, Random r, | 35 | int steps, int maxKey, String[] values, Random r, |
36 | int commitFrequency) { | 36 | int commitFrequency) { |
37 | VersionedMapStore<Integer, String> store1 = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 37 | VersionedMapStore<Integer, String> store1 = new VersionedMapStoreImpl<>(chp, values[0]); |
38 | VersionedMap<Integer, String> sut1 = store1.createMap(); | 38 | VersionedMap<Integer, String> sut1 = store1.createMap(); |
39 | 39 | ||
40 | // Fill one map | 40 | // Fill one map |
@@ -64,7 +64,7 @@ class ContentEqualsFuzzTest { | |||
64 | // Randomize the order of the content | 64 | // Randomize the order of the content |
65 | Collections.shuffle(content, r); | 65 | Collections.shuffle(content, r); |
66 | 66 | ||
67 | VersionedMapStore<Integer, String> store2 = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 67 | VersionedMapStore<Integer, String> store2 = new VersionedMapStoreImpl<>(chp, values[0]); |
68 | VersionedMap<Integer, String> sut2 = store2.createMap(); | 68 | VersionedMap<Integer, String> sut2 = store2.createMap(); |
69 | int index2 = 1; | 69 | int index2 = 1; |
70 | for (SimpleEntry<Integer, String> entry : content) { | 70 | for (SimpleEntry<Integer, String> entry : content) { |
@@ -95,7 +95,7 @@ class ContentEqualsFuzzTest { | |||
95 | static Stream<Arguments> parametrizedFastFuzz() { | 95 | static Stream<Arguments> parametrizedFastFuzz() { |
96 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, | 96 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, |
97 | 32 * 32}, | 97 | 32 * 32}, |
98 | new Object[]{2, 3}, new Object[]{false,true}, new Object[]{1, 10, 100}, new Object[]{1, 2, 3}, | 98 | new Object[]{2, 3}, new Object[]{false, true}, new Object[]{1, 10, 100}, new Object[]{1, 2, 3}, |
99 | new Object[]{false, true}); | 99 | new Object[]{false, true}); |
100 | } | 100 | } |
101 | 101 | ||
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java index 670b5445..4f7f48b5 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/DiffCursorFuzzTest.java | |||
@@ -22,11 +22,11 @@ import tools.refinery.store.map.tests.utils.MapTestEnvironment; | |||
22 | class DiffCursorFuzzTest { | 22 | class DiffCursorFuzzTest { |
23 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 23 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
24 | boolean nullDefault, int commitFrequency, | 24 | boolean nullDefault, int commitFrequency, |
25 | boolean evilHash) { | 25 | boolean evilHash) { |
26 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 26 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
27 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 27 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
28 | 28 | ||
29 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 29 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); |
30 | iterativeRandomPutsAndCommitsThenDiffCursor(scenario, store, steps, maxKey, values, seed, commitFrequency); | 30 | iterativeRandomPutsAndCommitsThenDiffCursor(scenario, store, steps, maxKey, values, seed, commitFrequency); |
31 | } | 31 | } |
32 | 32 | ||
@@ -62,7 +62,7 @@ class DiffCursorFuzzTest { | |||
62 | for (int i = 0; i < steps; i++) { | 62 | for (int i = 0; i < steps; i++) { |
63 | int index = i + 1; | 63 | int index = i + 1; |
64 | if (index % diffTravelFrequency == 0) { | 64 | if (index % diffTravelFrequency == 0) { |
65 | // difftravel | 65 | // diff-travel |
66 | long travelToVersion = r2.nextInt(largestCommit + 1); | 66 | long travelToVersion = r2.nextInt(largestCommit + 1); |
67 | DiffCursor<Integer, String> diffCursor = moving.getDiffCursor(travelToVersion); | 67 | DiffCursor<Integer, String> diffCursor = moving.getDiffCursor(travelToVersion); |
68 | moving.putAll(diffCursor); | 68 | moving.putAll(diffCursor); |
@@ -94,16 +94,17 @@ class DiffCursorFuzzTest { | |||
94 | @Tag("fuzz") | 94 | @Tag("fuzz") |
95 | void parametrizedFuzz(int tests, int steps, int noKeys, int noValues, boolean nullDefault, int commitFrequency, | 95 | void parametrizedFuzz(int tests, int steps, int noKeys, int noValues, boolean nullDefault, int commitFrequency, |
96 | int seed, | 96 | int seed, |
97 | boolean evilHash) { | 97 | boolean evilHash) { |
98 | runFuzzTest("MutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, | 98 | runFuzzTest("MutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, |
99 | noKeys, noValues, nullDefault, commitFrequency, evilHash); | 99 | noKeys, noValues, nullDefault, commitFrequency, evilHash); |
100 | } | 100 | } |
101 | 101 | ||
102 | static Stream<Arguments> parametrizedFuzz() { | 102 | static Stream<Arguments> parametrizedFuzz() { |
103 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, | 103 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, 32 * 32}, |
104 | new Object[] { 2, 3 }, new Object[]{false,true}, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | 104 | new Object[]{2, 3}, new Object[]{false, true}, new Object[]{1, 10, 100}, new Object[]{1, 2, 3}, |
105 | new Object[] { false, true }); | 105 | new Object[]{false, true}); |
106 | } | 106 | } |
107 | |||
107 | @ParameterizedTest(name = "Mutable-Immutable Compare {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} " + | 108 | @ParameterizedTest(name = "Mutable-Immutable Compare {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} " + |
108 | "commit frequency={5} seed={6} evil-hash={7}") | 109 | "commit frequency={5} seed={6} evil-hash={7}") |
109 | @MethodSource | 110 | @MethodSource |
@@ -111,7 +112,7 @@ class DiffCursorFuzzTest { | |||
111 | @Tag("slow") | 112 | @Tag("slow") |
112 | void parametrizedSlowFuzz(int tests, int steps, int noKeys, int noValues, boolean nullDefault, int commitFrequency, | 113 | void parametrizedSlowFuzz(int tests, int steps, int noKeys, int noValues, boolean nullDefault, int commitFrequency, |
113 | int seed, | 114 | int seed, |
114 | boolean evilHash) { | 115 | boolean evilHash) { |
115 | runFuzzTest("MutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, | 116 | runFuzzTest("MutableImmutableCompareS" + steps + "K" + noKeys + "V" + noValues + "s" + seed, seed, steps, noKeys, noValues, |
116 | nullDefault, commitFrequency, evilHash); | 117 | nullDefault, commitFrequency, evilHash); |
117 | } | 118 | } |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadFuzzTest.java index d8e1a30f..5412d958 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadFuzzTest.java | |||
@@ -26,64 +26,64 @@ class MultiThreadFuzzTest { | |||
26 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 26 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
27 | boolean nullDefault, int commitFrequency, | 27 | boolean nullDefault, int commitFrequency, |
28 | boolean evilHash) { | 28 | boolean evilHash) { |
29 | String[] values = MapTestEnvironment.prepareValues(maxValue,nullDefault); | 29 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
30 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 30 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
31 | 31 | ||
32 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 32 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); |
33 | 33 | ||
34 | // initialize runnables | 34 | // initialize runnables |
35 | MultiThreadTestRunnable[] runnables = new MultiThreadTestRunnable[noThreads]; | 35 | MultiThreadTestRunnable[] runnables = new MultiThreadTestRunnable[noThreads]; |
36 | for(int i = 0; i<noThreads; i++) { | 36 | for (int i = 0; i < noThreads; i++) { |
37 | runnables[i] = new MultiThreadTestRunnable(scenario+"-T"+(i+1), store, steps, maxKey, values, seed, commitFrequency); | 37 | runnables[i] = new MultiThreadTestRunnable(scenario + "-T" + (i + 1), store, steps, maxKey, values, seed, commitFrequency); |
38 | } | 38 | } |
39 | 39 | ||
40 | // initialize threads | 40 | // initialize threads |
41 | Thread[] threads = new Thread[noThreads]; | 41 | Thread[] threads = new Thread[noThreads]; |
42 | for(int i = 0; i<noThreads; i++) { | 42 | for (int i = 0; i < noThreads; i++) { |
43 | threads[i] = new Thread(runnables[i]); | 43 | threads[i] = new Thread(runnables[i]); |
44 | } | 44 | } |
45 | 45 | ||
46 | // start threads; | 46 | // start threads; |
47 | for(int i = 0; i<noThreads; i++) { | 47 | for (int i = 0; i < noThreads; i++) { |
48 | threads[i].start(); | 48 | threads[i].start(); |
49 | } | 49 | } |
50 | 50 | ||
51 | // wait all the threads; | 51 | // wait all the threads; |
52 | for(int i = 0; i<noThreads; i++) { | 52 | for (int i = 0; i < noThreads; i++) { |
53 | try { | 53 | try { |
54 | threads[i].join(); | 54 | threads[i].join(); |
55 | } catch (InterruptedException e) { | 55 | } catch (InterruptedException e) { |
56 | fail("Thread "+i+" interrupted."); | 56 | fail("Thread " + i + " interrupted."); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | // collect errors | 60 | // collect errors |
61 | List<Throwable> errors = new LinkedList<>(); | 61 | List<Throwable> errors = new LinkedList<>(); |
62 | for(int i = 0; i<noThreads; i++) { | 62 | for (int i = 0; i < noThreads; i++) { |
63 | errors.addAll(runnables[i].getErrors()); | 63 | errors.addAll(runnables[i].getErrors()); |
64 | } | 64 | } |
65 | 65 | ||
66 | assertEquals(Collections.EMPTY_LIST, errors); | 66 | assertEquals(Collections.EMPTY_LIST, errors); |
67 | } | 67 | } |
68 | 68 | ||
69 | @ParameterizedTest(name = "Multithread {index}/{0} Steps={1} Keys={2} Values={3} defaultNull={4} commit " + | 69 | @ParameterizedTest(name = "MultiThread {index}/{0} Steps={1} Keys={2} Values={3} defaultNull={4} commit " + |
70 | "frequency={5} seed={6} evil-hash={7}") | 70 | "frequency={5} seed={6} evil-hash={7}") |
71 | @MethodSource | 71 | @MethodSource |
72 | @Timeout(value = 10) | 72 | @Timeout(value = 10) |
73 | @Tag("fuzz") | 73 | @Tag("fuzz") |
74 | void parametrizedFastFuzz(int tests, int steps, int noKeys, int noValues, boolean defaultNull, int commitFrequency, | 74 | void parametrizedFastFuzz(int tests, int steps, int noKeys, int noValues, boolean defaultNull, int commitFrequency, |
75 | int seed, boolean evilHash) { | 75 | int seed, boolean evilHash) { |
76 | runFuzzTest("MultithreadS" + steps + "K" + noKeys + "V" + noValues + defaultNull + "CF" + commitFrequency + | 76 | runFuzzTest("MultiThreadS" + steps + "K" + noKeys + "V" + noValues + defaultNull + "CF" + commitFrequency + |
77 | "s" + seed, seed, steps, noKeys, noValues, defaultNull, commitFrequency, evilHash); | 77 | "s" + seed, seed, steps, noKeys, noValues, defaultNull, commitFrequency, evilHash); |
78 | } | 78 | } |
79 | 79 | ||
80 | static Stream<Arguments> parametrizedFastFuzz() { | 80 | static Stream<Arguments> parametrizedFastFuzz() { |
81 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, | 81 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, 32 * 32}, |
82 | new Object[] { 2, 3 }, new Object[]{false, true}, new Object[] { 10, 100 }, new Object[] { 1, 2, 3 }, | 82 | new Object[]{2, 3}, new Object[]{false, true}, new Object[]{10, 100}, new Object[]{1, 2, 3}, |
83 | new Object[] { false, true }); | 83 | new Object[]{false, true}); |
84 | } | 84 | } |
85 | 85 | ||
86 | @ParameterizedTest(name = "Multithread {index}/{0} Steps={1} Keys={2} Values={3} defaultNull={4} commit " + | 86 | @ParameterizedTest(name = "MultiThread {index}/{0} Steps={1} Keys={2} Values={3} defaultNull={4} commit " + |
87 | "frequency={5} seed={6} evil-hash={7}") | 87 | "frequency={5} seed={6} evil-hash={7}") |
88 | @MethodSource | 88 | @MethodSource |
89 | @Tag("fuzz") | 89 | @Tag("fuzz") |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java index f77f9ee5..4415e4e5 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MultiThreadTestRunnable.java | |||
@@ -13,17 +13,17 @@ import tools.refinery.store.map.internal.VersionedMapImpl; | |||
13 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 13 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
14 | 14 | ||
15 | public class MultiThreadTestRunnable implements Runnable { | 15 | public class MultiThreadTestRunnable implements Runnable { |
16 | String scenario; | 16 | final String scenario; |
17 | VersionedMapStore<Integer, String> store; | 17 | final VersionedMapStore<Integer, String> store; |
18 | int steps; | 18 | final int steps; |
19 | int maxKey; | 19 | final int maxKey; |
20 | String[] values; | 20 | final String[] values; |
21 | int seed; | 21 | final int seed; |
22 | int commitFrequency; | 22 | final int commitFrequency; |
23 | List<Throwable> errors = new LinkedList<>(); | 23 | final List<Throwable> errors = new LinkedList<>(); |
24 | 24 | ||
25 | public MultiThreadTestRunnable(String scenario, VersionedMapStore<Integer, String> store, int steps, | 25 | public MultiThreadTestRunnable(String scenario, VersionedMapStore<Integer, String> store, int steps, |
26 | int maxKey, String[] values, int seed, int commitFrequency) { | 26 | int maxKey, String[] values, int seed, int commitFrequency) { |
27 | super(); | 27 | super(); |
28 | this.scenario = scenario; | 28 | this.scenario = scenario; |
29 | this.store = store; | 29 | this.store = store; |
@@ -38,11 +38,11 @@ public class MultiThreadTestRunnable implements Runnable { | |||
38 | AssertionError error = new AssertionError(message); | 38 | AssertionError error = new AssertionError(message); |
39 | errors.add(error); | 39 | errors.add(error); |
40 | } | 40 | } |
41 | 41 | ||
42 | public List<Throwable> getErrors() { | 42 | public List<Throwable> getErrors() { |
43 | return errors; | 43 | return errors; |
44 | } | 44 | } |
45 | 45 | ||
46 | @Override | 46 | @Override |
47 | public void run() { | 47 | public void run() { |
48 | // 1. build a map with versions | 48 | // 1. build a map with versions |
@@ -66,10 +66,10 @@ public class MultiThreadTestRunnable implements Runnable { | |||
66 | } | 66 | } |
67 | MapTestEnvironment.printStatus(scenario, index, steps, "building"); | 67 | MapTestEnvironment.printStatus(scenario, index, steps, "building"); |
68 | } | 68 | } |
69 | // 2. create a non-versioned | 69 | // 2. create a non-versioned |
70 | VersionedMapImpl<Integer, String> reference = (VersionedMapImpl<Integer, String>) store.createMap(); | 70 | VersionedMapImpl<Integer, String> reference = (VersionedMapImpl<Integer, String>) store.createMap(); |
71 | r = new Random(seed); | 71 | r = new Random(seed); |
72 | Random r2 = new Random(seed+1); | 72 | Random r2 = new Random(seed + 1); |
73 | 73 | ||
74 | for (int i = 0; i < steps; i++) { | 74 | for (int i = 0; i < steps; i++) { |
75 | int index = i + 1; | 75 | int index = i + 1; |
@@ -84,12 +84,12 @@ public class MultiThreadTestRunnable implements Runnable { | |||
84 | // go back to an existing state and compare to the reference | 84 | // go back to an existing state and compare to the reference |
85 | if (index % (commitFrequency) == 0) { | 85 | if (index % (commitFrequency) == 0) { |
86 | versioned.restore(index2Version.get(i)); | 86 | versioned.restore(index2Version.get(i)); |
87 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned,errors); | 87 | MapTestEnvironment.compareTwoMaps(scenario + ":" + index, reference, versioned, errors); |
88 | 88 | ||
89 | // go back to a random state (probably created by another thread) | 89 | // go back to a random state (probably created by another thread) |
90 | List<Long> states = new ArrayList<>(store.getStates()); | 90 | List<Long> states = new ArrayList<>(store.getStates()); |
91 | Collections.shuffle(states, r2); | 91 | Collections.shuffle(states, r2); |
92 | for(Long state : states.subList(0, Math.min(states.size(), 100))) { | 92 | for (Long state : states.subList(0, Math.min(states.size(), 100))) { |
93 | versioned.restore(state); | 93 | versioned.restore(state); |
94 | } | 94 | } |
95 | versioned.restore(index2Version.get(i)); | 95 | versioned.restore(index2Version.get(i)); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableFuzzTest.java index 008258bd..2448268a 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableFuzzTest.java | |||
@@ -21,12 +21,12 @@ import tools.refinery.store.map.tests.utils.MapTestEnvironment; | |||
21 | class MutableFuzzTest { | 21 | class MutableFuzzTest { |
22 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 22 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
23 | boolean nullDefault, boolean evilHash) { | 23 | boolean nullDefault, boolean evilHash) { |
24 | String[] values = MapTestEnvironment.prepareValues(maxValue,nullDefault); | 24 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
25 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 25 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
26 | 26 | ||
27 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 27 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); |
28 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); | 28 | VersionedMapImpl<Integer, String> sut = (VersionedMapImpl<Integer, String>) store.createMap(); |
29 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<Integer, String>(sut); | 29 | MapTestEnvironment<Integer, String> e = new MapTestEnvironment<>(sut); |
30 | 30 | ||
31 | Random r = new Random(seed); | 31 | Random r = new Random(seed); |
32 | 32 | ||
@@ -34,24 +34,14 @@ class MutableFuzzTest { | |||
34 | } | 34 | } |
35 | 35 | ||
36 | private void iterativeRandomPuts(String scenario, int steps, int maxKey, String[] values, | 36 | private void iterativeRandomPuts(String scenario, int steps, int maxKey, String[] values, |
37 | MapTestEnvironment<Integer, String> e, Random r) { | 37 | MapTestEnvironment<Integer, String> e, Random r) { |
38 | int stopAt = -1; | ||
39 | for (int i = 0; i < steps; i++) { | 38 | for (int i = 0; i < steps; i++) { |
40 | int index = i + 1; | 39 | int index = i + 1; |
41 | int nextKey = r.nextInt(maxKey); | 40 | int nextKey = r.nextInt(maxKey); |
42 | String nextValue = values[r.nextInt(values.length)]; | 41 | String nextValue = values[r.nextInt(values.length)]; |
43 | if (index == stopAt) { | 42 | |
44 | System.out.println("issue!"); | ||
45 | System.out.println("State before:"); | ||
46 | e.printComparison(); | ||
47 | e.sut.prettyPrint(); | ||
48 | System.out.println("Next: put(" + nextKey + "," + nextValue + ")"); | ||
49 | } | ||
50 | try { | 43 | try { |
51 | e.put(nextKey, nextValue); | 44 | e.put(nextKey, nextValue); |
52 | if (index == stopAt) { | ||
53 | e.sut.prettyPrint(); | ||
54 | } | ||
55 | e.checkEquivalence(scenario + ":" + index); | 45 | e.checkEquivalence(scenario + ":" + index); |
56 | } catch (Exception exception) { | 46 | } catch (Exception exception) { |
57 | exception.printStackTrace(); | 47 | exception.printStackTrace(); |
@@ -74,9 +64,9 @@ class MutableFuzzTest { | |||
74 | } | 64 | } |
75 | 65 | ||
76 | static Stream<Arguments> parametrizedFuzz() { | 66 | static Stream<Arguments> parametrizedFuzz() { |
77 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, | 67 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, |
78 | new Object[] { 3, 32, 32 * 32, 32 * 32 * 32 * 32 }, new Object[] { 2, 3 }, new Object[] { false, true }, | 68 | new Object[]{3, 32, 32 * 32, 32 * 32 * 32 * 32}, new Object[]{2, 3}, new Object[]{false, true}, |
79 | new Object[] { 1, 2, 3 }, new Object[] { false, true }); | 69 | new Object[]{1, 2, 3}, new Object[]{false, true}); |
80 | } | 70 | } |
81 | 71 | ||
82 | @ParameterizedTest(name = "Mutable {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} seed={5} " + | 72 | @ParameterizedTest(name = "Mutable {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} seed={5} " + |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java index 6e15b8ca..07ca4f69 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java | |||
@@ -24,7 +24,7 @@ class MutableImmutableCompareFuzzTest { | |||
24 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 24 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
25 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 25 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
26 | 26 | ||
27 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 27 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); |
28 | VersionedMapImpl<Integer, String> immutable = (VersionedMapImpl<Integer, String>) store.createMap(); | 28 | VersionedMapImpl<Integer, String> immutable = (VersionedMapImpl<Integer, String>) store.createMap(); |
29 | VersionedMapImpl<Integer, String> mutable = (VersionedMapImpl<Integer, String>) store.createMap(); | 29 | VersionedMapImpl<Integer, String> mutable = (VersionedMapImpl<Integer, String>) store.createMap(); |
30 | 30 | ||
@@ -35,8 +35,8 @@ class MutableImmutableCompareFuzzTest { | |||
35 | } | 35 | } |
36 | 36 | ||
37 | private void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapImpl<Integer, String> immutable, | 37 | private void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapImpl<Integer, String> immutable, |
38 | VersionedMapImpl<Integer, String> mutable, int steps, int maxKey, String[] values, Random r, | 38 | VersionedMapImpl<Integer, String> mutable, int steps, int maxKey, String[] values, Random r, |
39 | int commitFrequency) { | 39 | int commitFrequency) { |
40 | for (int i = 0; i < steps; i++) { | 40 | for (int i = 0; i < steps; i++) { |
41 | int index = i + 1; | 41 | int index = i + 1; |
42 | int nextKey = r.nextInt(maxKey); | 42 | int nextKey = r.nextInt(maxKey); |
@@ -69,9 +69,9 @@ class MutableImmutableCompareFuzzTest { | |||
69 | } | 69 | } |
70 | 70 | ||
71 | static Stream<Arguments> parametrizedFastFuzz() { | 71 | static Stream<Arguments> parametrizedFastFuzz() { |
72 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, | 72 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, 32 * 32}, |
73 | new Object[] { 2, 3 }, new Object[]{false,true}, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | 73 | new Object[]{2, 3}, new Object[]{false, true}, new Object[]{1, 10, 100}, new Object[]{1, 2, 3}, |
74 | new Object[] { false, true }); | 74 | new Object[]{false, true}); |
75 | } | 75 | } |
76 | 76 | ||
77 | @ParameterizedTest(name = "Mutable-Immutable Compare {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} " + | 77 | @ParameterizedTest(name = "Mutable-Immutable Compare {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} " + |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java index 35a54712..e0366381 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/RestoreFuzzTest.java | |||
@@ -23,17 +23,17 @@ import tools.refinery.store.map.tests.utils.MapTestEnvironment; | |||
23 | class RestoreFuzzTest { | 23 | class RestoreFuzzTest { |
24 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 24 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
25 | boolean nullDefault, int commitFrequency, | 25 | boolean nullDefault, int commitFrequency, |
26 | boolean evilHash) { | 26 | boolean evilHash) { |
27 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 27 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
28 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 28 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
29 | 29 | ||
30 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(chp, values[0]); | 30 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); |
31 | 31 | ||
32 | iterativeRandomPutsAndCommitsThenRestore(scenario, store, steps, maxKey, values, seed, commitFrequency); | 32 | iterativeRandomPutsAndCommitsThenRestore(scenario, store, steps, maxKey, values, seed, commitFrequency); |
33 | } | 33 | } |
34 | 34 | ||
35 | private void iterativeRandomPutsAndCommitsThenRestore(String scenario, VersionedMapStore<Integer, String> store, | 35 | private void iterativeRandomPutsAndCommitsThenRestore(String scenario, VersionedMapStore<Integer, String> store, |
36 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { | 36 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { |
37 | // 1. build a map with versions | 37 | // 1. build a map with versions |
38 | Random r = new Random(seed); | 38 | Random r = new Random(seed); |
39 | VersionedMapImpl<Integer, String> versioned = (VersionedMapImpl<Integer, String>) store.createMap(); | 39 | VersionedMapImpl<Integer, String> versioned = (VersionedMapImpl<Integer, String>) store.createMap(); |
@@ -90,9 +90,9 @@ class RestoreFuzzTest { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | static Stream<Arguments> parametrizedFastFuzz() { | 92 | static Stream<Arguments> parametrizedFastFuzz() { |
93 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, | 93 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, 32 * 32}, |
94 | new Object[] { 2, 3 }, new Object[]{false, true}, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | 94 | new Object[]{2, 3}, new Object[]{false, true}, new Object[]{1, 10, 100}, new Object[]{1, 2, 3}, |
95 | new Object[] { false, true }); | 95 | new Object[]{false, true}); |
96 | } | 96 | } |
97 | 97 | ||
98 | @ParameterizedTest(name = "Restore {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} commit frequency={5}" + | 98 | @ParameterizedTest(name = "Restore {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} commit frequency={5}" + |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java index ac033edb..a576b1c8 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java | |||
@@ -32,22 +32,22 @@ class SharedStoreFuzzTest { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | private void iterativeRandomPutsAndCommitsThenRestore(String scenario, List<VersionedMapStore<Integer, String>> stores, | 34 | private void iterativeRandomPutsAndCommitsThenRestore(String scenario, List<VersionedMapStore<Integer, String>> stores, |
35 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { | 35 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { |
36 | // 1. maps with versions | 36 | // 1. maps with versions |
37 | Random r = new Random(seed); | 37 | Random r = new Random(seed); |
38 | List<VersionedMapImpl<Integer, String>> versioneds = new LinkedList<>(); | 38 | List<VersionedMapImpl<Integer, String>> versioneds = new LinkedList<>(); |
39 | for(VersionedMapStore<Integer, String> store : stores) { | 39 | for (VersionedMapStore<Integer, String> store : stores) { |
40 | versioneds.add((VersionedMapImpl<Integer, String>) store.createMap()); | 40 | versioneds.add((VersionedMapImpl<Integer, String>) store.createMap()); |
41 | } | 41 | } |
42 | 42 | ||
43 | List<Map<Integer, Long>> index2Version = new LinkedList<>(); | 43 | List<Map<Integer, Long>> index2Version = new LinkedList<>(); |
44 | for(int i = 0; i<stores.size(); i++) { | 44 | for (int i = 0; i < stores.size(); i++) { |
45 | index2Version.add(new HashMap<>()); | 45 | index2Version.add(new HashMap<>()); |
46 | } | 46 | } |
47 | 47 | ||
48 | for (int i = 0; i < steps; i++) { | 48 | for (int i = 0; i < steps; i++) { |
49 | int stepIndex = i + 1; | 49 | int stepIndex = i + 1; |
50 | for (int storeIndex = 0; storeIndex<versioneds.size(); storeIndex++) { | 50 | for (int storeIndex = 0; storeIndex < versioneds.size(); storeIndex++) { |
51 | int nextKey = r.nextInt(maxKey); | 51 | int nextKey = r.nextInt(maxKey); |
52 | String nextValue = values[r.nextInt(values.length)]; | 52 | String nextValue = values[r.nextInt(values.length)]; |
53 | versioneds.get(storeIndex).put(nextKey, nextValue); | 53 | versioneds.get(storeIndex).put(nextKey, nextValue); |
@@ -60,14 +60,14 @@ class SharedStoreFuzzTest { | |||
60 | } | 60 | } |
61 | // 2. create a non-versioned and | 61 | // 2. create a non-versioned and |
62 | List<VersionedMapImpl<Integer, String>> reference = new LinkedList<>(); | 62 | List<VersionedMapImpl<Integer, String>> reference = new LinkedList<>(); |
63 | for(VersionedMapStore<Integer, String> store : stores) { | 63 | for (VersionedMapStore<Integer, String> store : stores) { |
64 | reference.add((VersionedMapImpl<Integer, String>) store.createMap()); | 64 | reference.add((VersionedMapImpl<Integer, String>) store.createMap()); |
65 | } | 65 | } |
66 | r = new Random(seed); | 66 | r = new Random(seed); |
67 | 67 | ||
68 | for (int i = 0; i < steps; i++) { | 68 | for (int i = 0; i < steps; i++) { |
69 | int index = i + 1; | 69 | int index = i + 1; |
70 | for (int storeIndex = 0; storeIndex<versioneds.size(); storeIndex++) { | 70 | for (int storeIndex = 0; storeIndex < versioneds.size(); storeIndex++) { |
71 | int nextKey = r.nextInt(maxKey); | 71 | int nextKey = r.nextInt(maxKey); |
72 | String nextValue = values[r.nextInt(values.length)]; | 72 | String nextValue = values[r.nextInt(values.length)]; |
73 | reference.get(storeIndex).put(nextKey, nextValue); | 73 | reference.get(storeIndex).put(nextKey, nextValue); |
@@ -93,9 +93,9 @@ class SharedStoreFuzzTest { | |||
93 | } | 93 | } |
94 | 94 | ||
95 | static Stream<Arguments> parametrizedFastFuzz() { | 95 | static Stream<Arguments> parametrizedFastFuzz() { |
96 | return FuzzTestUtils.permutationWithSize(new Object[] { FuzzTestUtils.FAST_STEP_COUNT }, new Object[] { 3, 32, 32 * 32 }, | 96 | return FuzzTestUtils.permutationWithSize(new Object[]{FuzzTestUtils.FAST_STEP_COUNT}, new Object[]{3, 32, 32 * 32}, |
97 | new Object[] { 2, 3 }, new Object[]{false, true}, new Object[] { 1, 10, 100 }, new Object[] { 1, 2, 3 }, | 97 | new Object[]{2, 3}, new Object[]{false, true}, new Object[]{1, 10, 100}, new Object[]{1, 2, 3}, |
98 | new Object[] { false, true }); | 98 | new Object[]{false, true}); |
99 | } | 99 | } |
100 | 100 | ||
101 | @ParameterizedTest(name = "Shared Store {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} commit " + | 101 | @ParameterizedTest(name = "Shared Store {index}/{0} Steps={1} Keys={2} Values={3} nullDefault={4} commit " + |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtils.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtils.java index e75d7f5a..92208e48 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtils.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtils.java | |||
@@ -51,14 +51,12 @@ public final class FuzzTestUtils { | |||
51 | 51 | ||
52 | public static Stream<Arguments> permutationWithSize(Object[]... valueOption) { | 52 | public static Stream<Arguments> permutationWithSize(Object[]... valueOption) { |
53 | int size = 1; | 53 | int size = 1; |
54 | for (int i = 0; i < valueOption.length; i++) { | 54 | for (Object[] objects : valueOption) { |
55 | size *= valueOption[i].length; | 55 | size *= objects.length; |
56 | } | 56 | } |
57 | Object[][] newValueOption = new Object[valueOption.length + 1][]; | 57 | Object[][] newValueOption = new Object[valueOption.length + 1][]; |
58 | newValueOption[0] = new Object[] { size }; | 58 | newValueOption[0] = new Object[]{size}; |
59 | for (int i = 1; i < newValueOption.length; i++) { | 59 | System.arraycopy(valueOption, 0, newValueOption, 1, newValueOption.length - 1); |
60 | newValueOption[i] = valueOption[i - 1]; | ||
61 | } | ||
62 | return permutation(newValueOption); | 60 | return permutation(newValueOption); |
63 | } | 61 | } |
64 | } | 62 | } |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtilsTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtilsTest.java index 72f2a46c..8c641205 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtilsTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/utils/FuzzTestUtilsTest.java | |||
@@ -1,31 +1,36 @@ | |||
1 | package tools.refinery.store.map.tests.fuzz.utils; | 1 | package tools.refinery.store.map.tests.fuzz.utils; |
2 | 2 | ||
3 | import static org.junit.jupiter.api.Assertions.assertEquals; | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | import static org.junit.jupiter.api.Assertions.assertTrue; | ||
4 | 5 | ||
5 | import java.util.List; | 6 | import java.util.List; |
7 | import java.util.Optional; | ||
6 | 8 | ||
7 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
10 | import org.junit.jupiter.params.provider.Arguments; | ||
8 | 11 | ||
9 | class FuzzTestUtilsTest { | 12 | class FuzzTestUtilsTest { |
10 | @Test | 13 | @Test |
11 | void permutationInternalTest() { | 14 | void permutationInternalTest() { |
12 | List<List<Object>> res = FuzzTestUtils.permutationInternal(0, new Object[] { 1, 2, 3 }, | 15 | List<List<Object>> res = FuzzTestUtils.permutationInternal(0, new Object[]{1, 2, 3}, |
13 | new Object[] { 'a', 'b', 'c' }, new Object[] { "alpha", "beta", "gamma", "delta" }); | 16 | new Object[]{'a', 'b', 'c'}, new Object[]{"alpha", "beta", "gamma", "delta"}); |
14 | assertEquals(3 * 3 * 4, res.size()); | 17 | assertEquals(3 * 3 * 4, res.size()); |
15 | } | 18 | } |
16 | 19 | ||
17 | @Test | 20 | @Test |
18 | void permutationTest1() { | 21 | void permutationTest1() { |
19 | var res = FuzzTestUtils.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, | 22 | var res = FuzzTestUtils.permutation(new Object[]{1, 2, 3}, new Object[]{'a', 'b', 'c'}, |
20 | new Object[] { "alpha", "beta", "gamma", "delta" }); | 23 | new Object[]{"alpha", "beta", "gamma", "delta"}); |
21 | assertEquals(3 * 3 * 4, res.count()); | 24 | assertEquals(3 * 3 * 4, res.count()); |
22 | } | 25 | } |
23 | 26 | ||
24 | @Test | 27 | @Test |
25 | void permutationTest2() { | 28 | void permutationTest2() { |
26 | var res = FuzzTestUtils.permutation(new Object[] { 1, 2, 3 }, new Object[] { 'a', 'b', 'c' }, | 29 | var res = FuzzTestUtils.permutation(new Object[]{1, 2, 3}, new Object[]{'a', 'b', 'c'}, |
27 | new Object[] { "alpha", "beta", "gamma", "delta" }); | 30 | new Object[]{"alpha", "beta", "gamma", "delta"}); |
28 | var arguments = res.findFirst().get().get(); | 31 | Optional<Arguments> first = res.findFirst(); |
32 | assertTrue(first.isPresent()); | ||
33 | var arguments = first.get().get(); | ||
29 | assertEquals(1, arguments[0]); | 34 | assertEquals(1, arguments[0]); |
30 | assertEquals('a', arguments[1]); | 35 | assertEquals('a', arguments[1]); |
31 | assertEquals("alpha", arguments[2]); | 36 | assertEquals("alpha", arguments[2]); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java index 10ea2796..30f38201 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java | |||
@@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.*; | |||
11 | public class MapTestEnvironment<K, V> { | 11 | public class MapTestEnvironment<K, V> { |
12 | public static String[] prepareValues(int maxValue, boolean nullDefault) { | 12 | public static String[] prepareValues(int maxValue, boolean nullDefault) { |
13 | String[] values = new String[maxValue]; | 13 | String[] values = new String[maxValue]; |
14 | if(nullDefault) { | 14 | if (nullDefault) { |
15 | values[0] = null; | 15 | values[0] = null; |
16 | } else { | 16 | } else { |
17 | values[0] = "DEFAULT"; | 17 | values[0] = "DEFAULT"; |
@@ -26,23 +26,18 @@ public class MapTestEnvironment<K, V> { | |||
26 | public static ContinousHashProvider<Integer> prepareHashProvider(final boolean evil) { | 26 | public static ContinousHashProvider<Integer> prepareHashProvider(final boolean evil) { |
27 | // Use maxPrime = 2147483629 | 27 | // Use maxPrime = 2147483629 |
28 | 28 | ||
29 | ContinousHashProvider<Integer> chp = new ContinousHashProvider<Integer>() { | 29 | return (key, index) -> { |
30 | 30 | if (evil && index < 15 && index < key / 3) { | |
31 | @Override | 31 | return 7; |
32 | public int getHash(Integer key, int index) { | 32 | } |
33 | if (evil && index < 15 && index < key / 3) { | 33 | int result = 1; |
34 | return 7; | 34 | final int prime = 31; |
35 | } | ||
36 | int result = 1; | ||
37 | final int prime = 31; | ||
38 | 35 | ||
39 | result = prime * result + key; | 36 | result = prime * result + key; |
40 | result = prime * result + index; | 37 | result = prime * result + index; |
41 | 38 | ||
42 | return result; | 39 | return result; |
43 | } | ||
44 | }; | 40 | }; |
45 | return chp; | ||
46 | } | 41 | } |
47 | 42 | ||
48 | public static void printStatus(String scenario, int actual, int max, String stepName) { | 43 | public static void printStatus(String scenario, int actual, int max, String stepName) { |