Test that a sequence remains "valid" after is has been modified.

This commit is contained in:
2021-08-29 21:30:30 +02:00
parent f7a424e7ae
commit 9a23fc4b27

View File

@ -24,6 +24,8 @@ public abstract class SequenceProcessorTest<S> {
@ArgumentsSource(ListProvider.class) @ArgumentsSource(ListProvider.class)
void testThat_createAndIterateWork(List<Integer> list) { void testThat_createAndIterateWork(List<Integer> list) {
S s = processor.create(list); S s = processor.create(list);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -69,6 +71,8 @@ public abstract class SequenceProcessorTest<S> {
S s = processor.create(list); S s = processor.create(list);
assertFalse(processor.override(s, -1, -5)); assertFalse(processor.override(s, -1, -5));
assertFalse(processor.override(s, 999, -5)); assertFalse(processor.override(s, 999, -5));
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -82,6 +86,7 @@ public abstract class SequenceProcessorTest<S> {
assertTrue(processor.override(s, list.get(i), to)); assertTrue(processor.override(s, list.get(i), to));
list.set(i, to); list.set(i, to);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
} }
@ -92,6 +97,8 @@ public abstract class SequenceProcessorTest<S> {
S s = processor.create(list); S s = processor.create(list);
assertFalse(processor.overrideAll(s, -1, -5)); assertFalse(processor.overrideAll(s, -1, -5));
assertFalse(processor.overrideAll(s, 999, -5)); assertFalse(processor.overrideAll(s, 999, -5));
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -107,6 +114,7 @@ public abstract class SequenceProcessorTest<S> {
list.replaceAll(k -> list.replaceAll(k ->
Objects.equals(k, from) ? to : k); Objects.equals(k, from) ? to : k);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
} }
@ -117,6 +125,8 @@ public abstract class SequenceProcessorTest<S> {
S s = processor.create(list); S s = processor.create(list);
assertFalse(processor.overrideAt(s, -5, -1)); assertFalse(processor.overrideAt(s, -5, -1));
assertFalse(processor.overrideAt(s, -5, 999)); assertFalse(processor.overrideAt(s, -5, 999));
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -130,6 +140,7 @@ public abstract class SequenceProcessorTest<S> {
assertTrue(processor.overrideAt(s, to, i)); assertTrue(processor.overrideAt(s, to, i));
list.set(i, to); list.set(i, to);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
} }
@ -146,6 +157,7 @@ public abstract class SequenceProcessorTest<S> {
list.add(i); list.add(i);
list.sort(cmp); list.sort(cmp);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
} }
@ -156,6 +168,8 @@ public abstract class SequenceProcessorTest<S> {
S s = processor.create(list); S s = processor.create(list);
assertFalse(processor.remove(s, -1)); assertFalse(processor.remove(s, -1));
assertFalse(processor.remove(s, 999)); assertFalse(processor.remove(s, 999));
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -170,6 +184,7 @@ public abstract class SequenceProcessorTest<S> {
list.remove(toRemove); list.remove(toRemove);
assertTrue(processor.remove(s, toRemove)); assertTrue(processor.remove(s, toRemove));
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
} }
@ -180,6 +195,8 @@ public abstract class SequenceProcessorTest<S> {
S s = processor.create(list); S s = processor.create(list);
assertFalse(processor.removeAll(s, -1)); assertFalse(processor.removeAll(s, -1));
assertFalse(processor.removeAll(s, 999)); assertFalse(processor.removeAll(s, 999));
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -194,6 +211,7 @@ public abstract class SequenceProcessorTest<S> {
list.removeAll(Collections.singleton(toRemove)); list.removeAll(Collections.singleton(toRemove));
assertTrue(processor.removeAll(s, toRemove)); assertTrue(processor.removeAll(s, toRemove));
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
} }
@ -367,6 +385,7 @@ public abstract class SequenceProcessorTest<S> {
.collect(Collectors.toList()); .collect(Collectors.toList());
processor.doubleAllKeys(s); processor.doubleAllKeys(s);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -382,6 +401,7 @@ public abstract class SequenceProcessorTest<S> {
s = processor.rotateRight(s); s = processor.rotateRight(s);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -397,6 +417,7 @@ public abstract class SequenceProcessorTest<S> {
s = processor.rotateLeft(s); s = processor.rotateLeft(s);
assertTrue(processor.check(s));
assertIterableEquals(list, processor.iterate(s)); assertIterableEquals(list, processor.iterate(s));
} }
@ -414,6 +435,7 @@ public abstract class SequenceProcessorTest<S> {
processor.removeDuplicates(s); processor.removeDuplicates(s);
assertTrue(processor.check(s));
assertIterableEquals(noDuplicatesList, processor.iterate(s)); assertIterableEquals(noDuplicatesList, processor.iterate(s));
} }
} }