@@ -276,4 +276,50 @@ public void testToIntArrayLittleEndian() {
276276 assertArrayEquals (new int []{257 , 1 }, Bytes .wrap (new byte []{1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toIntArray ());
277277 assertArrayEquals (new int []{257 , 65_793 , 1 }, Bytes .wrap (new byte []{1 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toIntArray ());
278278 }
279+
280+ @ Test
281+ public void testToLongArray () {
282+ assertArrayEquals (new long []{1 }, Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }).toLongArray ());
283+ assertArrayEquals (new long []{257 }, Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 }).toLongArray ());
284+ assertArrayEquals (new long []{3329575617569751109L }, Bytes .wrap (new byte []{46 , 53 , 7 , 98 , 34 , 12 , 0 , 69 }).toLongArray ());
285+ assertArrayEquals (new long []{-7124130559744646145L }, Bytes .wrap (new byte []{(byte ) 157 , 34 , 1 , 0 , 76 , (byte ) 234 , 99 , (byte ) 255 }).toLongArray ());
286+
287+ assertArrayEquals (new long []{1 , 1 }, Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }).toLongArray ());
288+ assertArrayEquals (new long []{257 , 1 }, Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }).toLongArray ());
289+ assertArrayEquals (new long []{1099511628033L , 281474976776449L , 1 }, Bytes .wrap (new byte []{
290+ 0 , 0 , 1 , 0 , 0 , 0 , 1 , 1 ,
291+ 0 , 1 , 0 , 0 , 0 , 1 , 1 , 1 ,
292+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }).toLongArray ());
293+ }
294+
295+ @ Test (expected = IllegalArgumentException .class )
296+ public void testToLongArrayNotMod4Was9Byte () {
297+ Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }).toLongArray ();
298+ }
299+
300+ @ Test (expected = IllegalArgumentException .class )
301+ public void testToLongArrayNotMod4Only7Byte () {
302+ Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 1 }).toLongArray ();
303+ }
304+
305+ @ Test
306+ public void testToLongEmptyArray () {
307+ assertArrayEquals (new long [0 ], Bytes .empty ().toLongArray ());
308+ }
309+
310+
311+ @ Test
312+ public void testToLongArrayLittleEndian () {
313+ assertArrayEquals (new long []{1 }, Bytes .wrap (new byte []{1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toLongArray ());
314+ assertArrayEquals (new long []{257 }, Bytes .wrap (new byte []{1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toLongArray ());
315+ assertArrayEquals (new long []{3329575617569751109L }, Bytes .wrap (new byte []{69 , 0 , 12 , 34 , 98 , 7 , 53 , 46 }, ByteOrder .LITTLE_ENDIAN ).toLongArray ());
316+ assertArrayEquals (new long []{-7124130559744646145L }, Bytes .wrap (new byte []{(byte ) 255 , 99 , (byte ) 234 , 76 , 0 , 1 , 34 , (byte ) 157 }, ByteOrder .LITTLE_ENDIAN ).toLongArray ());
317+
318+ assertArrayEquals (new long []{1 , 1 }, Bytes .wrap (new byte []{1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toLongArray ());
319+ assertArrayEquals (new long []{257 , 1 }, Bytes .wrap (new byte []{1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toLongArray ());
320+ assertArrayEquals (new long []{1099511628033L , 281474976776449L , 1 }, Bytes .wrap (new byte []{
321+ 1 , 1 , 0 , 0 , 0 , 1 , 0 , 0 ,
322+ 1 , 1 , 1 , 0 , 0 , 0 , 1 , 0 ,
323+ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, ByteOrder .LITTLE_ENDIAN ).toLongArray ());
324+ }
279325}
0 commit comments