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)); }
private static void testSortDescending(short[] input, short[] expectedOutput) { input = Arrays.copyOf(input, input.length); Shorts.sortDescending(input); assertTrue(Arrays.equals(expectedOutput, input)); }
private static void testReverse(short[] input, short[] expectedOutput) { input = Arrays.copyOf(input, input.length); Shorts.reverse(input); assertTrue(Arrays.equals(expectedOutput, input)); }
private static void testReverse( short[] input, int fromIndex, int toIndex, short[] expectedOutput) { input = Arrays.copyOf(input, input.length); Shorts.reverse(input, fromIndex, toIndex); assertTrue(Arrays.equals(expectedOutput, input)); }
public void testToArray() { // need explicit type parameter to avoid javac warning!? List<Short> none = Arrays.<Short>asList(); assertTrue(Arrays.equals(EMPTY, Shorts.toArray(none))); List<Short> one = Arrays.asList((short) 1); assertTrue(Arrays.equals(ARRAY1, Shorts.toArray(one))); short[] array = {(short) 0, (short) 1, (short) 3}; List<Short> three = Arrays.asList((short) 0, (short) 1, (short) 3); assertTrue(Arrays.equals(array, Shorts.toArray(three))); assertTrue(Arrays.equals(array, Shorts.toArray(Shorts.asList(array)))); }
public void testToArray_withConversion() { short[] array = {(short) 0, (short) 1, (short) 2}; List<Byte> bytes = Arrays.asList((byte) 0, (byte) 1, (byte) 2); List<Short> shorts = Arrays.asList((short) 0, (short) 1, (short) 2); List<Integer> ints = Arrays.asList(0, 1, 2); List<Float> floats = Arrays.asList((float) 0, (float) 1, (float) 2); List<Long> longs = Arrays.asList((long) 0, (long) 1, (long) 2); List<Double> doubles = Arrays.asList((double) 0, (double) 1, (double) 2); assertTrue(Arrays.equals(array, Shorts.toArray(bytes))); assertTrue(Arrays.equals(array, Shorts.toArray(shorts))); assertTrue(Arrays.equals(array, Shorts.toArray(ints))); assertTrue(Arrays.equals(array, Shorts.toArray(floats))); assertTrue(Arrays.equals(array, Shorts.toArray(longs))); assertTrue(Arrays.equals(array, Shorts.toArray(doubles))); }
public void testAsList_subList_toArray_roundTrip() { short[] array = {(short) 0, (short) 1, (short) 2, (short) 3}; List<Short> list = Shorts.asList(array); assertTrue( Arrays.equals(new short[] {(short) 1, (short) 2}, Shorts.toArray(list.subList(1, 3)))); assertTrue(Arrays.equals(new short[] {}, Shorts.toArray(list.subList(2, 2)))); }
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 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))); }
@GwtIncompatible // Shorts.toByteArray public void testToByteArray() { assertTrue(Arrays.equals(new byte[] {0x23, 0x45}, Shorts.toByteArray((short) 0x2345))); assertTrue( Arrays.equals(new byte[] {(byte) 0xFE, (byte) 0xDC}, Shorts.toByteArray((short) 0xFEDC))); }
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); }
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 testCompare() { for (short x : VALUES) { for (short y : VALUES) { // Only compare the sign of the result of compareTo(). int expected = Short.valueOf(x).compareTo(y); int actual = Shorts.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 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)); }
@GwtIncompatible // Shorts.fromByteArray, Shorts.toByteArray public void testByteArrayRoundTrips() { Random r = new Random(5); byte[] b = new byte[Shorts.BYTES]; // total overkill, but, it takes 0.1 sec so why not... for (int i = 0; i < 10000; i++) { short num = (short) r.nextInt(); assertEquals(num, Shorts.fromByteArray(Shorts.toByteArray(num))); r.nextBytes(b); assertTrue(Arrays.equals(b, Shorts.toByteArray(Shorts.fromByteArray(b)))); } }
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))); }
private static void testReverse(short[] input, short[] expectedOutput) { input = Arrays.copyOf(input, input.length); Shorts.reverse(input); assertTrue(Arrays.equals(expectedOutput, input)); }
public void testAsList_subList_toArray_roundTrip() { short[] array = { (short) 0, (short) 1, (short) 2, (short) 3 }; List<Short> list = Shorts.asList(array); assertTrue(Arrays.equals(new short[] { (short) 1, (short) 2 }, Shorts.toArray(list.subList(1, 3)))); assertTrue(Arrays.equals(new short[] {}, Shorts.toArray(list.subList(2, 2)))); }
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 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))); }