Transpose { private Transpose() { } private  Transpose(); static List<StrictBitVector> transpose(List<StrictBitVector> input);  }
@Test public void testSquareTranspose() { List<StrictBitVector> input = getSquareMatrix(); List<StrictBitVector> res = Transpose.transpose(input); for (int i = 0; i < 8; i++) { assertEquals((byte) 0x81, res.get(i).toByteArray()[0]); assertEquals((byte) 0x7E, res.get(i).toByteArray()[1]); } for (int i = 0; i < 8; i++) { assertEquals((byte) 0x81, res.get(i + 8).toByteArray()[0]); assertEquals((byte) 0x7E, res.get(i + 8).toByteArray()[1]); } }
@Test public void testWideTranspose() { List<StrictBitVector> input = new ArrayList<>( Arrays.asList( new StrictBitVector(new byte[] { (byte) 0xFF, (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0x00, (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00, (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00, (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00, (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00, (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00, (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0xFF, (byte) 0x00 }))); List<StrictBitVector> res = Transpose.transpose(input); for (int i = 0; i < 8; i++) { assertEquals((byte) 0x81, res.get(i).toByteArray()[0]); } for (int i = 0; i < 8; i++) { assertEquals((byte) 0x7E, res.get(8 + i).toByteArray()[0]); } }
@Test public void testTallTranspose() { List<StrictBitVector> input = new ArrayList<>( Arrays.asList( new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00 }), new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0xFF }), new StrictBitVector(new byte[] { (byte) 0x00 }))); List<StrictBitVector> res = Transpose.transpose(input); for (int i = 0; i < 8; i++) { assertEquals((byte) 0x81, res.get(i).toByteArray()[0]); } for (int i = 0; i < 8; i++) { assertEquals((byte) 0x7E, res.get(i).toByteArray()[1]); } }
@Test public void testWrongAmountOfRows() { boolean thrown; List<StrictBitVector> matrix = getSquareMatrix(); matrix.remove(0); thrown = false; try { Transpose.transpose(matrix); } catch (IllegalArgumentException e) { assertEquals("The amount rows in the matrix is not 8*2^x for some x > 1", e.getMessage()); thrown = true; } assertEquals(true, thrown); matrix = new ArrayList<>(); for (int i = 0; i < 24; i++) { matrix.add(new StrictBitVector(24)); } thrown = false; try { Transpose.transpose(matrix); } catch (IllegalArgumentException e) { assertEquals("The amount rows in the matrix is not 8*2^x for some x > 1", e.getMessage()); thrown = true; } assertEquals(true, thrown); }