stevedlawrence commented on a change in pull request #571:
URL: https://github.com/apache/daffodil/pull/571#discussion_r636143560



##########
File path: daffodil-lib/src/test/scala/passera/test/TestULong.scala
##########
@@ -64,5 +63,45 @@ class TestULong {
     val remainder = mm1 % mm2
     assertEquals(ULong(1), remainder)
   }
-  
+
+  @Test def testULongMostNegativeLong1: Unit = {
+    val v = ULong(Long.MinValue)
+    val vbi = v.toBigInt
+    val vhex = vbi.toString(16)
+    assertEquals("8000000000000000", vhex)
+    assertEquals("8000000000000000", v.toHexString)
+    assertEquals(-9223372036854775808L, v.longValue)
+    assertEquals("9223372036854775808", v.toString)
+  }
+
+  @Test def testULongMaxValue: Unit = {
+    val v = ULong.MaxValue
+    assertEquals("FFFFFFFFFFFFFFFF", v.toHexString.toUpperCase)
+    assertEquals(ULong(0), v + ULong(1))
+    val v1 = ULong.MaxValue.toBigInt.add(JBigInt.TWO) // 0x8000000000000001
+    assertEquals(ULong(1), ULong(v1)) // preserves only 64 bits
+  }
+
+  @Test def testULongFromBigInt: Unit = {
+    val zero = JBigInt.ZERO
+    val one = JBigInt.ONE
+    val two = JBigInt.TWO
+    val minusOne = JBigInt.valueOf(-1)
+    val minusTwo = JBigInt.valueOf(-2)
+    assertEquals(0, ULong(zero).toInt)
+    assertEquals(1, ULong(one).toInt)
+    assertEquals(2, ULong(two).toInt)
+    assertEquals(-1, ULong(minusOne).toInt)
+    assertEquals(-2, ULong(minusTwo).toInt)
+    assertEquals("7FFFFFFFFFFFFFFF", (ULong(Long.MinValue) - 
ULong(1)).toHexString.toUpperCase)
+  }
+
+  @Test def testULongShift: Unit = {
+    // NO sign extension since a ULong has no sign bit.
+    assertEquals("7FFFFFFFFFFFFFFF", (ULong.MaxValue >> 
1).toHexString.toUpperCase)
+    assertEquals("7FFFFFFFFFFFFFFF", (ULong.MaxValue >>> 
1).toHexString.toUpperCase)
+    assertEquals(1, (ULong.MaxValue >> 63).toInt)
+    assertEquals(ULong.MaxValue, ULong.MaxValue >> 64)

Review comment:
       Oh yeah, forgot about how Java modulo's the shift value. In which case, 
this is consistent with signed types and is perfectly reasonable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to