From 42fcbb71a7483666a5426ea5abea9736ec50e323 Mon Sep 17 00:00:00 2001 From: lax1dude Date: Mon, 2 Dec 2024 19:49:20 -0800 Subject: [PATCH] Add missing java.lang.Long unit tests --- .../teavm/classlib/java/lang/LongTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/LongTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/LongTest.java index 0920b99f3..183f05698 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/LongTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/LongTest.java @@ -86,6 +86,35 @@ public class LongTest { assertEquals(0xF63BA00000000000L, Long.reverse(0x5DC6F)); } + @Test + public void numberOfLeadingZerosComputed() { + assertEquals(0, Long.numberOfLeadingZeros(-1L)); + assertEquals(1, Long.numberOfLeadingZeros(0x4000000000000000L)); + assertEquals(1, Long.numberOfLeadingZeros(0x4000000000000123L)); + assertEquals(1, Long.numberOfLeadingZeros(0x7FFFFFFFFFFFFFFFL)); + assertEquals(63, Long.numberOfLeadingZeros(1L)); + assertEquals(62, Long.numberOfLeadingZeros(2L)); + assertEquals(62, Long.numberOfLeadingZeros(3L)); + assertEquals(0, Long.numberOfLeadingZeros(0x8000000000000000L)); + assertEquals(0, Long.numberOfLeadingZeros(0x8000000000000123L)); + assertEquals(0, Long.numberOfLeadingZeros(0xFFFFFFFFFFFFFFFFL)); + assertEquals(64, Long.numberOfLeadingZeros(0L)); + } + + @Test + public void numberOfTrailingZerosComputed() { + assertEquals(1, Long.numberOfTrailingZeros(0xFFFFFFFFFFFFFFFEL)); + assertEquals(1, Long.numberOfTrailingZeros(0x4000000000000002L)); + assertEquals(1, Long.numberOfTrailingZeros(0x0000000000000002L)); + assertEquals(63, Long.numberOfTrailingZeros(0x8000000000000000L)); + assertEquals(62, Long.numberOfTrailingZeros(0x4000000000000000L)); + assertEquals(62, Long.numberOfTrailingZeros(0xC000000000000000L)); + assertEquals(0, Long.numberOfTrailingZeros(0x0000000000000001L)); + assertEquals(0, Long.numberOfTrailingZeros(0x1230000000000003L)); + assertEquals(0, Long.numberOfTrailingZeros(0xFFFFFFFFFFFFFFFFL)); + assertEquals(64, Long.numberOfTrailingZeros(0L)); + } + @Test public void highestOneBit() { assertEquals(1L << 63, Long.highestOneBit(-1L));