@@ -406,4 +406,38 @@ public void testToDoubleArrayLittleEndian() {
406406 1 , 1 , 1 , 0 , 0 , 0 , 1 , 0 ,
407407 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toDoubleArray (), 0.01 );
408408 }
409+
410+ @ Test
411+ public void testToShortArrayEmpty () {
412+ assertArrayEquals (new short [0 ], Bytes .empty ().toShortArray ());
413+ }
414+
415+
416+ @ Test (expected = IllegalArgumentException .class )
417+ public void testToShortArrayNotMod2Was5Byte () {
418+ Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 1 }).toShortArray ();
419+ }
420+
421+ @ Test
422+ public void testToShortArray () {
423+ assertArrayEquals (new short []{1 }, Bytes .wrap (new byte []{0 , 1 }).toShortArray ());
424+ assertArrayEquals (new short []{257 }, Bytes .wrap (new byte []{1 , 1 }).toShortArray ());
425+ assertArrayEquals (new short []{32_767 }, Bytes .wrap (new byte []{127 , -1 }).toShortArray ());
426+
427+ assertArrayEquals (new short []{1 , 1 }, Bytes .wrap (new byte []{0 , 1 , 0 , 1 }).toShortArray ());
428+ assertArrayEquals (new short []{257 , 1 }, Bytes .wrap (new byte []{1 , 1 , 0 , 1 }).toShortArray ());
429+ assertArrayEquals (new short []{257 , 32_767 , 1 }, Bytes .wrap (new byte []{1 , 1 , 127 , -1 , 0 , 1 }).toShortArray ());
430+ }
431+
432+ @ Test
433+ public void testToShortArrayLittleEndian () {
434+ assertArrayEquals (new short []{1 }, Bytes .wrap (new byte []{1 , 0 }, ByteOrder .LITTLE_ENDIAN ).toShortArray ());
435+ assertArrayEquals (new short []{257 }, Bytes .wrap (new byte []{1 , 1 }, ByteOrder .LITTLE_ENDIAN ).toShortArray ());
436+ assertArrayEquals (new short []{32_767 }, Bytes .wrap (new byte []{-1 , 127 }, ByteOrder .LITTLE_ENDIAN ).toShortArray ());
437+
438+ assertArrayEquals (new short []{1 , 1 }, Bytes .wrap (new byte []{1 , 0 , 1 , 0 }, ByteOrder .LITTLE_ENDIAN ).toShortArray ());
439+ assertArrayEquals (new short []{257 , 1 }, Bytes .wrap (new byte []{1 , 1 , 1 , 0 }, ByteOrder .LITTLE_ENDIAN ).toShortArray ());
440+ assertArrayEquals (new short []{257 , 32_767 , 1 }, Bytes .wrap (new byte []{1 , 1 , -1 , 127 , 1 , 0 }, ByteOrder .LITTLE_ENDIAN ).toShortArray ());
441+ }
442+
409443}
0 commit comments