public void testCheckedCast() { for (short value : VALUES) { assertEquals(value, Shorts.checkedCast((long) value)); } assertCastFails(GREATEST + 1L); assertCastFails(LEAST - 1L); assertCastFails(Long.MAX_VALUE); assertCastFails(Long.MIN_VALUE); }
public void testContains() { assertFalse(Shorts.contains(EMPTY, (short) 1)); assertFalse(Shorts.contains(ARRAY1, (short) 2)); assertFalse(Shorts.contains(ARRAY234, (short) 1)); assertTrue(Shorts.contains(new short[] {(short) -1}, (short) -1)); assertTrue(Shorts.contains(ARRAY234, (short) 2)); assertTrue(Shorts.contains(ARRAY234, (short) 3)); assertTrue(Shorts.contains(ARRAY234, (short) 4)); }
public void testConcat() { assertTrue(Arrays.equals(EMPTY, Shorts.concat())); assertTrue(Arrays.equals(EMPTY, Shorts.concat(EMPTY))); assertTrue(Arrays.equals(EMPTY, Shorts.concat(EMPTY, EMPTY, EMPTY))); assertTrue(Arrays.equals(ARRAY1, Shorts.concat(ARRAY1))); assertNotSame(ARRAY1, Shorts.concat(ARRAY1)); assertTrue(Arrays.equals(ARRAY1, Shorts.concat(EMPTY, ARRAY1, EMPTY))); assertTrue( Arrays.equals( new short[] {(short) 1, (short) 1, (short) 1}, Shorts.concat(ARRAY1, ARRAY1, ARRAY1))); assertTrue( Arrays.equals( new short[] {(short) 1, (short) 2, (short) 3, (short) 4}, Shorts.concat(ARRAY1, ARRAY234))); }
public void testAsList_isAView() { short[] array = {(short) 0, (short) 1}; List<Short> list = Shorts.asList(array); list.set(0, (short) 2); assertTrue(Arrays.equals(new short[] {(short) 2, (short) 1}, array)); array[1] = (short) 3; assertEquals(Arrays.asList((short) 2, (short) 3), list); }
private static void assertCastFails(long value) { try { Shorts.checkedCast(value); fail("Cast to short should have failed: " + value); } catch (IllegalArgumentException ex) { assertTrue( value + " not found in exception text: " + ex.getMessage(), ex.getMessage().contains(String.valueOf(value))); } }
public void testMin() { assertEquals(LEAST, Shorts.min(LEAST)); assertEquals(GREATEST, Shorts.min(GREATEST)); assertEquals( (short) 0, Shorts.min((short) 8, (short) 6, (short) 7, (short) 5, (short) 3, (short) 0, (short) 9)); }
private static void testSortDescending( short[] input, int fromIndex, int toIndex, short[] expectedOutput) { input = Arrays.copyOf(input, input.length); Shorts.sortDescending(input, fromIndex, toIndex); assertTrue(Arrays.equals(expectedOutput, input)); }
public void testMax_noArgs() { try { Shorts.max(); fail(); } catch (IllegalArgumentException expected) { } }
public void testConstrainToRange() { assertEquals((short) 1, Shorts.constrainToRange((short) 1, (short) 0, (short) 5)); assertEquals((short) 1, Shorts.constrainToRange((short) 1, (short) 1, (short) 5)); assertEquals((short) 3, Shorts.constrainToRange((short) 1, (short) 3, (short) 5)); assertEquals((short) -1, Shorts.constrainToRange((short) 0, (short) -5, (short) -1)); assertEquals((short) 2, Shorts.constrainToRange((short) 5, (short) 2, (short) 2)); try { Shorts.constrainToRange((short) 1, (short) 3, (short) 2); fail(); } catch (IllegalArgumentException expected) { } }
public void testEnsureCapacity() { assertSame(EMPTY, Shorts.ensureCapacity(EMPTY, 0, 1)); assertSame(ARRAY1, Shorts.ensureCapacity(ARRAY1, 0, 1)); assertSame(ARRAY1, Shorts.ensureCapacity(ARRAY1, 1, 1)); assertTrue( Arrays.equals( new short[] {(short) 1, (short) 0, (short) 0}, Shorts.ensureCapacity(ARRAY1, 2, 1))); }
public void testReverseIndexed() { testReverse(new short[] {}, 0, 0, new short[] {}); testReverse(new short[] {1}, 0, 1, new short[] {1}); testReverse(new short[] {1, 2}, 0, 2, new short[] {2, 1}); testReverse(new short[] {3, 1, 1}, 0, 2, new short[] {1, 3, 1}); testReverse(new short[] {3, 1, 1}, 0, 1, new short[] {3, 1, 1}); testReverse(new short[] {-1, 1, -2, 2}, 1, 3, new short[] {-1, -2, 1, 2}); }
public void testSortDescendingIndexed() { testSortDescending(new short[] {}, 0, 0, new short[] {}); testSortDescending(new short[] {1}, 0, 1, new short[] {1}); testSortDescending(new short[] {1, 2}, 0, 2, new short[] {2, 1}); testSortDescending(new short[] {1, 3, 1}, 0, 2, new short[] {3, 1, 1}); testSortDescending(new short[] {1, 3, 1}, 0, 1, new short[] {1, 3, 1}); testSortDescending(new short[] {-1, -2, 1, 2}, 1, 3, new short[] {-1, 1, -2, 2}); }
public void testAsListEmpty() { assertSame(Collections.emptyList(), Shorts.asList(EMPTY)); }
public void testStringConverter_nullConversions() { assertNull(Shorts.stringConverter().convert(null)); assertNull(Shorts.stringConverter().reverse().convert(null)); }
public void testAsList_toArray_roundTrip() { short[] array = {(short) 0, (short) 1, (short) 2}; List<Short> list = Shorts.asList(array); short[] newArray = Shorts.toArray(list); // Make sure it returned a copy list.set(0, (short) 4); assertTrue(Arrays.equals(new short[] {(short) 0, (short) 1, (short) 2}, newArray)); newArray[1] = (short) 5; assertEquals((short) 1, (short) list.get(1)); }
public void testSaturatedCast() { for (short value : VALUES) { assertEquals(value, Shorts.saturatedCast((long) value)); } assertEquals(GREATEST, Shorts.saturatedCast(GREATEST + 1L)); assertEquals(LEAST, Shorts.saturatedCast(LEAST - 1L)); assertEquals(GREATEST, Shorts.saturatedCast(Long.MAX_VALUE)); assertEquals(LEAST, Shorts.saturatedCast(Long.MIN_VALUE)); }
private static void testReverse(short[] input, short[] expectedOutput) { input = Arrays.copyOf(input, input.length); Shorts.reverse(input); assertTrue(Arrays.equals(expectedOutput, input)); }
public void testMin_noArgs() { try { Shorts.min(); fail(); } catch (IllegalArgumentException expected) { } }
public void testConstrainToRange() { assertEquals((short) 1, Shorts.constrainToRange((short) 1, (short) 0, (short) 5)); assertEquals((short) 1, Shorts.constrainToRange((short) 1, (short) 1, (short) 5)); assertEquals((short) 3, Shorts.constrainToRange((short) 1, (short) 3, (short) 5)); assertEquals((short) -1, Shorts.constrainToRange((short) 0, (short) -5, (short) -1)); assertEquals((short) 2, Shorts.constrainToRange((short) 5, (short) 2, (short) 2)); try { Shorts.constrainToRange((short) 1, (short) 3, (short) 2); fail(); } catch (IllegalArgumentException expected) { } }
public void testEnsureCapacity() { assertSame(EMPTY, Shorts.ensureCapacity(EMPTY, 0, 1)); assertSame(ARRAY1, Shorts.ensureCapacity(ARRAY1, 0, 1)); assertSame(ARRAY1, Shorts.ensureCapacity(ARRAY1, 1, 1)); assertTrue(Arrays.equals( new short[] {(short) 1, (short) 0, (short) 0}, Shorts.ensureCapacity(ARRAY1, 2, 1))); }