public void testCheckedCast() { for (byte value : VALUES) { assertEquals(value, SignedBytes.checkedCast((long) value)); } assertCastFails(GREATEST + 1L); assertCastFails(LEAST - 1L); assertCastFails(Long.MAX_VALUE); assertCastFails(Long.MIN_VALUE); }
private static void assertCastFails(long value) { try { SignedBytes.checkedCast(value); fail("Cast to byte should have failed: " + value); } catch (IllegalArgumentException ex) { assertTrue( value + " not found in exception text: " + ex.getMessage(), ex.getMessage().contains(String.valueOf(value))); } }
public void testSortDescending() { testSortDescending(new byte[] {}, new byte[] {}); testSortDescending(new byte[] {1}, new byte[] {1}); testSortDescending(new byte[] {1, 2}, new byte[] {2, 1}); testSortDescending(new byte[] {1, 3, 1}, new byte[] {3, 1, 1}); testSortDescending(new byte[] {-1, 1, -2, 2}, new byte[] {2, 1, -1, -2}); }
public void testCompare() { for (byte x : VALUES) { for (byte y : VALUES) { // Only compare the sign of the result of compareTo(). int expected = Byte.valueOf(x).compareTo(y); int actual = SignedBytes.compare(x, y); if (expected == 0) { assertEquals(x + ", " + y, expected, actual); } else if (expected < 0) { assertTrue( x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual < 0); } else { assertTrue( x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual > 0); } } } }
public void testSaturatedCast() { for (byte value : VALUES) { assertEquals(value, SignedBytes.saturatedCast((long) value)); } assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L)); assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L)); assertEquals(GREATEST, SignedBytes.saturatedCast(Long.MAX_VALUE)); assertEquals(LEAST, SignedBytes.saturatedCast(Long.MIN_VALUE)); }
private static void testSortDescending(byte[] input, byte[] expectedOutput) { input = Arrays.copyOf(input, input.length); SignedBytes.sortDescending(input); assertTrue(Arrays.equals(expectedOutput, input)); }
public void testMax_noArgs() { try { SignedBytes.max(); fail(); } catch (IllegalArgumentException expected) { } }
@GwtIncompatible // SerializableTester public void testLexicographicalComparatorSerializable() { Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); assertSame(comparator, SerializableTester.reserialize(comparator)); }
public void testMax() { assertEquals(LEAST, SignedBytes.max(LEAST)); assertEquals(GREATEST, SignedBytes.max(GREATEST)); assertEquals( (byte) 127, SignedBytes.max((byte) 0, (byte) -128, (byte) -1, (byte) 127, (byte) 1)); }
public void testCompare() { for (byte x : VALUES) { for (byte y : VALUES) { // Only compare the sign of the result of compareTo(). int expected = Byte.valueOf(x).compareTo(y); int actual = SignedBytes.compare(x, y); if (expected == 0) { assertEquals(x + ", " + y, expected, actual); } else if (expected < 0) { assertTrue(x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual < 0); } else { assertTrue(x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual > 0); } } } }
private static void testSortDescending( byte[] input, int fromIndex, int toIndex, byte[] expectedOutput) { input = Arrays.copyOf(input, input.length); SignedBytes.sortDescending(input, fromIndex, toIndex); assertTrue(Arrays.equals(expectedOutput, input)); }
public void testMin_noArgs() { try { SignedBytes.min(); fail(); } catch (IllegalArgumentException expected) { } }
@GwtIncompatible // SerializableTester public void testLexicographicalComparatorSerializable() { Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); assertSame(comparator, SerializableTester.reserialize(comparator)); }
private static void assertCastFails(long value) { try { SignedBytes.checkedCast(value); fail("Cast to byte should have failed: " + value); } catch (IllegalArgumentException ex) { assertTrue(value + " not found in exception text: " + ex.getMessage(), ex.getMessage().contains(String.valueOf(value))); } }
public void testJoin() { assertEquals("", SignedBytes.join(",", EMPTY)); assertEquals("1", SignedBytes.join(",", ARRAY1)); assertEquals("1,2", SignedBytes.join(",", (byte) 1, (byte) 2)); assertEquals("123", SignedBytes.join("", (byte) 1, (byte) 2, (byte) 3)); assertEquals("-128,-1", SignedBytes.join(",", (byte) -128, (byte) -1)); }
public void testCheckedCast() { for (byte value : VALUES) { assertEquals(value, SignedBytes.checkedCast((long) value)); } assertCastFails(GREATEST + 1L); assertCastFails(LEAST - 1L); assertCastFails(Long.MAX_VALUE); assertCastFails(Long.MIN_VALUE); }
public void testSortDescendingIndexed() { testSortDescending(new byte[] {}, 0, 0, new byte[] {}); testSortDescending(new byte[] {1}, 0, 1, new byte[] {1}); testSortDescending(new byte[] {1, 2}, 0, 2, new byte[] {2, 1}); testSortDescending(new byte[] {1, 3, 1}, 0, 2, new byte[] {3, 1, 1}); testSortDescending(new byte[] {1, 3, 1}, 0, 1, new byte[] {1, 3, 1}); testSortDescending(new byte[] {-1, -2, 1, 2}, 1, 3, new byte[] {-1, 1, -2, 2}); }
private static void testSortDescending( byte[] input, int fromIndex, int toIndex, byte[] expectedOutput) { input = Arrays.copyOf(input, input.length); SignedBytes.sortDescending(input, fromIndex, toIndex); assertTrue(Arrays.equals(expectedOutput, input)); }
public void testMin_noArgs() { try { SignedBytes.min(); fail(); } catch (IllegalArgumentException expected) { } }
public void testMin() { assertEquals(LEAST, SignedBytes.min(LEAST)); assertEquals(GREATEST, SignedBytes.min(GREATEST)); assertEquals( (byte) -128, SignedBytes.min((byte) 0, (byte) -128, (byte) -1, (byte) 127, (byte) 1)); }