public void testIncrementBytes() throws IOException { assertTrue(checkTestIncrementBytes(10, 1)); assertTrue(checkTestIncrementBytes(12, 123435445)); assertTrue(checkTestIncrementBytes(124634654, 1)); assertTrue(checkTestIncrementBytes(10005460, 5005645)); assertTrue(checkTestIncrementBytes(1, -1)); assertTrue(checkTestIncrementBytes(10, -1)); assertTrue(checkTestIncrementBytes(10, -5)); assertTrue(checkTestIncrementBytes(1005435000, -5)); assertTrue(checkTestIncrementBytes(10, -43657655)); assertTrue(checkTestIncrementBytes(-1, 1)); assertTrue(checkTestIncrementBytes(-26, 5034520)); assertTrue(checkTestIncrementBytes(-10657200, 5)); assertTrue(checkTestIncrementBytes(-12343250, 45376475)); assertTrue(checkTestIncrementBytes(-10, -5)); assertTrue(checkTestIncrementBytes(-12343250, -5)); assertTrue(checkTestIncrementBytes(-12, -34565445)); assertTrue(checkTestIncrementBytes(-1546543452, -34565445)); }
public void testGetBytesForByteBuffer() { byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ByteBuffer target = ByteBuffer.wrap(array); target.position(2); target.limit(7); byte[] actual = Bytes.getBytes(target); byte[] expected = { 2, 3, 4, 5, 6 }; assertTrue(Arrays.equals(expected, actual)); assertEquals(2, target.position()); assertEquals(7, target.limit()); }
public void testStartsWith() { assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h"))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes(""))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("hello"))); assertFalse(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("helloworld"))); assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello"))); }
public void testSplit2() throws Exception { // More split tests. byte [] lowest = Bytes.toBytes("http://A"); byte [] highest = Bytes.toBytes("http://z"); byte [] middle = Bytes.toBytes("http://]"); byte [][] parts = Bytes.split(lowest, highest, 1); for (int i = 0; i < parts.length; i++) { System.out.println(Bytes.toString(parts[i])); } assertEquals(3, parts.length); assertTrue(Bytes.equals(parts[1], middle)); }
public void testContains() { byte[] array = Bytes.toBytes("hello world"); assertTrue(Bytes.contains(array, (byte) 'e')); assertTrue(Bytes.contains(array, (byte) 'd')); assertFalse( Bytes.contains(array, (byte) 'a')); assertTrue(Bytes.contains(array, Bytes.toBytes("world"))); assertTrue(Bytes.contains(array, Bytes.toBytes("ello"))); assertFalse(Bytes.contains(array, Bytes.toBytes("owo"))); }
public void testToBytesForByteBuffer() { byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ByteBuffer target = ByteBuffer.wrap(array); target.position(2); target.limit(7); byte[] actual = Bytes.toBytes(target); byte[] expected = { 0, 1, 2, 3, 4, 5, 6 }; assertTrue(Arrays.equals(expected, actual)); assertEquals(2, target.position()); assertEquals(7, target.limit()); ByteBuffer target2 = target.slice(); assertEquals(0, target2.position()); assertEquals(5, target2.limit()); byte[] actual2 = Bytes.toBytes(target2); byte[] expected2 = { 2, 3, 4, 5, 6 }; assertTrue(Arrays.equals(expected2, actual2)); assertEquals(0, target2.position()); assertEquals(5, target2.limit()); }
public void testSplit() throws Exception { byte [] lowest = Bytes.toBytes("AAA"); byte [] middle = Bytes.toBytes("CCC"); byte [] highest = Bytes.toBytes("EEE"); byte [][] parts = Bytes.split(lowest, highest, 1); for (int i = 0; i < parts.length; i++) { System.out.println(Bytes.toString(parts[i])); } assertEquals(3, parts.length); assertTrue(Bytes.equals(parts[1], middle)); // Now divide into three parts. Change highest so split is even. highest = Bytes.toBytes("DDD"); parts = Bytes.split(lowest, highest, 2); for (int i = 0; i < parts.length; i++) { System.out.println(Bytes.toString(parts[i])); } assertEquals(4, parts.length); // Assert that 3rd part is 'CCC'. assertTrue(Bytes.equals(parts[2], middle)); }
public void testCopy() throws Exception { byte [] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); byte [] copy = Bytes.copy(bytes); assertFalse(bytes == copy); assertTrue(Bytes.equals(bytes, copy)); }
public void testSplit3() throws Exception { // Test invalid split cases byte [] low = { 1, 1, 1 }; byte [] high = { 1, 1, 3 }; // If swapped, should throw IAE try { Bytes.split(high, low, 1); assertTrue("Should not be able to split if low > high", false); } catch(IllegalArgumentException iae) { // Correct } // Single split should work byte [][] parts = Bytes.split(low, high, 1); for (int i = 0; i < parts.length; i++) { System.out.println("" + i + " -> " + Bytes.toStringBinary(parts[i])); } assertTrue("Returned split should have 3 parts but has " + parts.length, parts.length == 3); // If split more than once, use additional byte to split parts = Bytes.split(low, high, 2); assertTrue("Split with an additional byte", parts != null); assertEquals(parts.length, low.length + 1); // Split 0 times should throw IAE try { parts = Bytes.split(low, high, 0); assertTrue("Should not be able to split 0 times", false); } catch(IllegalArgumentException iae) { // Correct } }
public void testGetBytesForByteBuffer() { byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ByteBuffer target = ByteBuffer.wrap(array); target.position(2); target.limit(7); byte[] actual = Bytes.getBytes(target); byte[] expected = { 2, 3, 4, 5, 6 }; assertTrue(Arrays.equals(expected, actual)); assertEquals(2, target.position()); assertEquals(7, target.limit()); }
public void testStartsWith() { assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h"))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes(""))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("hello"))); assertFalse(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("helloworld"))); assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello"))); }
public void testStartsWith() { assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h"))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes(""))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("hello"))); assertFalse(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("helloworld"))); assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello"))); }
public void testSplit2() throws Exception { // More split tests. byte [] lowest = Bytes.toBytes("http://A"); byte [] highest = Bytes.toBytes("http://z"); byte [] middle = Bytes.toBytes("http://]"); byte [][] parts = Bytes.split(lowest, highest, 1); for (int i = 0; i < parts.length; i++) { System.out.println(Bytes.toString(parts[i])); } assertEquals(3, parts.length); assertTrue(Bytes.equals(parts[1], middle)); }
public void testGetBytesForByteBuffer() { byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ByteBuffer target = ByteBuffer.wrap(array); target.position(2); target.limit(7); byte[] actual = Bytes.getBytes(target); byte[] expected = { 2, 3, 4, 5, 6 }; assertTrue(Arrays.equals(expected, actual)); assertEquals(2, target.position()); assertEquals(7, target.limit()); }
public void testSplit2() throws Exception { // More split tests. byte [] lowest = Bytes.toBytes("http://A"); byte [] highest = Bytes.toBytes("http://z"); byte [] middle = Bytes.toBytes("http://]"); byte [][] parts = Bytes.split(lowest, highest, 1); for (int i = 0; i < parts.length; i++) { System.out.println(Bytes.toString(parts[i])); } assertEquals(3, parts.length); assertTrue(Bytes.equals(parts[1], middle)); }
public void testContains() { byte[] array = Bytes.toBytes("hello world"); assertTrue(Bytes.contains(array, (byte) 'e')); assertTrue(Bytes.contains(array, (byte) 'd')); assertFalse( Bytes.contains(array, (byte) 'a')); assertTrue(Bytes.contains(array, Bytes.toBytes("world"))); assertTrue(Bytes.contains(array, Bytes.toBytes("ello"))); assertFalse(Bytes.contains(array, Bytes.toBytes("owo"))); }
public void testContains() { byte[] array = Bytes.toBytes("hello world"); assertTrue(Bytes.contains(array, (byte) 'e')); assertTrue(Bytes.contains(array, (byte) 'd')); assertFalse( Bytes.contains(array, (byte) 'a')); assertTrue(Bytes.contains(array, Bytes.toBytes("world"))); assertTrue(Bytes.contains(array, Bytes.toBytes("ello"))); assertFalse(Bytes.contains(array, Bytes.toBytes("owo"))); }
public void testToBytesForByteBuffer() { byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ByteBuffer target = ByteBuffer.wrap(array); target.position(2); target.limit(7); byte[] actual = Bytes.toBytes(target); byte[] expected = { 0, 1, 2, 3, 4, 5, 6 }; assertTrue(Arrays.equals(expected, actual)); assertEquals(2, target.position()); assertEquals(7, target.limit()); ByteBuffer target2 = target.slice(); assertEquals(0, target2.position()); assertEquals(5, target2.limit()); byte[] actual2 = Bytes.toBytes(target2); byte[] expected2 = { 2, 3, 4, 5, 6 }; assertTrue(Arrays.equals(expected2, actual2)); assertEquals(0, target2.position()); assertEquals(5, target2.limit()); }
public void testCopy() throws Exception { byte [] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); byte [] copy = Bytes.copy(bytes); assertFalse(bytes == copy); assertTrue(Bytes.equals(bytes, copy)); }
public void testCopy() throws Exception { byte [] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); byte [] copy = Bytes.copy(bytes); assertFalse(bytes == copy); assertTrue(Bytes.equals(bytes, copy)); }