From 5a3e2b295c110e703dc8fcd6ab536c4400226353 Mon Sep 17 00:00:00 2001 From: Oshgnacknak Date: Mon, 30 Aug 2021 14:56:00 +0200 Subject: [PATCH] Implement exchangePairs and rotateTriples --- .../prep/array/FullyUsedArrayProcessor.java | 23 +++++++++----- test/aud/exam/prep/SequenceProcessorTest.java | 31 +++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/aud/exam/prep/array/FullyUsedArrayProcessor.java b/src/aud/exam/prep/array/FullyUsedArrayProcessor.java index 446abba..7e5a292 100644 --- a/src/aud/exam/prep/array/FullyUsedArrayProcessor.java +++ b/src/aud/exam/prep/array/FullyUsedArrayProcessor.java @@ -201,11 +201,6 @@ public class FullyUsedArrayProcessor implements SequenceProcessor array) { - return true; - } - @Override public boolean isItemWiseLessOrEqual(FullyUsedArray a, FullyUsedArray b, Comparator cmp) { if (b.theArray.length < a.theArray.length) { @@ -258,12 +253,21 @@ public class FullyUsedArrayProcessor implements SequenceProcessor array) { - + for (int i = 1; i < array.theArray.length-1; i += 2) { + T t = array.theArray[i]; + array.theArray[i] = array.theArray[i+1]; + array.theArray[i+1] = t; + } } @Override public void rotateTriples(FullyUsedArray array) { - + for (int i = 1; i < array.theArray.length-2; i += 3) { + T t = array.theArray[i+2]; + array.theArray[i+2] = array.theArray[i+1]; + array.theArray[i+1] = array.theArray[i]; + array.theArray[i] = t; + } } @Override @@ -514,6 +518,11 @@ public class FullyUsedArrayProcessor implements SequenceProcessor array) { + return true; + } + @Override public FullyUsedArray create(Iterable iterable) { var array = new FullyUsedArray(); diff --git a/test/aud/exam/prep/SequenceProcessorTest.java b/test/aud/exam/prep/SequenceProcessorTest.java index d5a132e..2ce9e1b 100644 --- a/test/aud/exam/prep/SequenceProcessorTest.java +++ b/test/aud/exam/prep/SequenceProcessorTest.java @@ -373,6 +373,37 @@ public abstract class SequenceProcessorTest { return processor.create(list); } + @ParameterizedTest + @ArgumentsSource(ListProvider.class) + void testThat_exchangePairsWorks(List list) { + S s = processor.create(list); + + for (int i = 1; i < list.size()-1; i += 2) { + Collections.swap(list, i, i+1); + } + + processor.exchangePairs(s); + + assertTrue(processor.check(s)); + assertIterableEquals(list, processor.iterate(s)); + } + + @ParameterizedTest + @ArgumentsSource(ListProvider.class) + void testThat_rotateTriplesWorks(List list) { + S s = processor.create(list); + + for (int i = 1; i < list.size()-2; i += 3) { + Collections.swap(list, i+1, i+2); + Collections.swap(list, i, i+1); + } + + processor.rotateTriples(s); + + assertTrue(processor.check(s)); + assertIterableEquals(list, processor.iterate(s)); + } + @ParameterizedTest @ArgumentsSource(ListProvider.class) void testThat_doubleAllKeysWorks(List list) {