GeometryEncoder implements StereoEncoder { @Override public boolean encode(long[] current, long[] next) { int p = permutation.parity(current); if (p != 0) { int q = geometric.parity() * p; if (q > 0) { for (int i : centres) { next[i] = current[i] * ANTICLOCKWISE; } } else if (q < 0) { for (int i : centres) { next[i] = current[i] * CLOCKWISE; } } return true; } return false; } GeometryEncoder(int[] centres, PermutationParity permutation, GeometricParity geometric);  GeometryEncoder(int centre, PermutationParity permutation, GeometricParity geometric); @Override boolean encode(long[] current, long[] next); @Override void reset();  }
@Test public void testConstruction_Singleton() { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(-1); when(geometric.parity()).thenReturn(+1); StereoEncoder encoder = new GeometryEncoder(1, permutation, geometric); long[] prev = new long[3]; long[] result = new long[3]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 15543053, 1})); }
@Test public void testEncode_Clockwise() throws Exception { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(-1); when(geometric.parity()).thenReturn(+1); StereoEncoder encoder = new GeometryEncoder(new int[]{1}, permutation, geometric); long[] prev = new long[3]; long[] result = new long[3]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 15543053, 1})); }
@Test public void testEncode_Clockwise_Alt() throws Exception { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(+1); when(geometric.parity()).thenReturn(-1); StereoEncoder encoder = new GeometryEncoder(new int[]{1}, permutation, geometric); long[] prev = new long[3]; long[] result = new long[3]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 15543053, 1})); }
@Test public void testEncode_Clockwise_Two() throws Exception { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(-1); when(geometric.parity()).thenReturn(+1); StereoEncoder encoder = new GeometryEncoder(new int[]{1, 3}, permutation, geometric); long[] prev = new long[6]; long[] result = new long[6]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 15543053, 1, 15543053, 1, 1})); }
@Test public void testEncode_Anticlockwise() throws Exception { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(+1); when(geometric.parity()).thenReturn(+1); StereoEncoder encoder = new GeometryEncoder(new int[]{1}, permutation, geometric); long[] prev = new long[3]; long[] result = new long[3]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 15521419, 1})); }
@Test public void testEncode_Anticlockwise_Alt() throws Exception { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(-1); when(geometric.parity()).thenReturn(-1); StereoEncoder encoder = new GeometryEncoder(new int[]{1}, permutation, geometric); long[] prev = new long[3]; long[] result = new long[3]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 15521419, 1})); }
@Test public void testEncode_Anticlockwise_Two() throws Exception { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(+1); when(geometric.parity()).thenReturn(+1); StereoEncoder encoder = new GeometryEncoder(new int[]{1, 3}, permutation, geometric); long[] prev = new long[6]; long[] result = new long[6]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 15521419, 1, 15521419, 1, 1})); }
@Test public void testEncode_NoGeometry() { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(+1); when(geometric.parity()).thenReturn(0); StereoEncoder encoder = new GeometryEncoder(new int[]{1, 3}, permutation, geometric); long[] prev = new long[6]; long[] result = new long[6]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertTrue(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 1, 1, 1, 1, 1})); }
@Test public void testEncode_NoPermutation() { PermutationParity permutation = mock(PermutationParity.class); GeometricParity geometric = mock(GeometricParity.class); when(permutation.parity(any(long[].class))).thenReturn(0); when(geometric.parity()).thenReturn(+1); StereoEncoder encoder = new GeometryEncoder(new int[]{1, 3}, permutation, geometric); long[] prev = new long[6]; long[] result = new long[6]; Arrays.fill(prev, 1); Arrays.fill(result, 1); assertFalse(encoder.encode(prev, result)); assertThat(result, is(new long[]{1, 1, 1, 1, 1, 1})); verify(geometric, never()).parity(); }