summary refs log tree commit diff
path: root/crypto/test/src/util/utiltest/LongsTest.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-06-01 14:11:19 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-06-01 14:11:19 +0700
commit0f23f1ffd16324dfb4045822ba6d39b32c775989 (patch)
treeb756cb4759fc0dc7acd0c03ef894fc5e195b4199 /crypto/test/src/util/utiltest/LongsTest.cs
parentCorrection (diff)
downloadBouncyCastle.NET-ed25519-0f23f1ffd16324dfb4045822ba6d39b32c775989.tar.xz
NTZ for 0 should be 32/64 resp.
- add tests for NLZ, NTZ
- round out methods for Longs class
Diffstat (limited to '')
-rw-r--r--crypto/test/src/util/utiltest/LongsTest.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/crypto/test/src/util/utiltest/LongsTest.cs b/crypto/test/src/util/utiltest/LongsTest.cs
new file mode 100644
index 000000000..b2ddb6656
--- /dev/null
+++ b/crypto/test/src/util/utiltest/LongsTest.cs
@@ -0,0 +1,36 @@
+using System;
+
+using NUnit.Framework;
+
+namespace Org.BouncyCastle.Utilities.UtilTests
+{
+    [TestFixture]
+    public class LongsTest
+    {
+        [Test]
+        public void TestNumberOfLeadingZeros()
+        {
+            for (int i = 0; i < 63; ++i)
+            {
+                Assert.AreEqual(i, Longs.NumberOfLeadingZeros((long)(0x8000000000000000UL >> i)));
+                Assert.AreEqual(i, Longs.NumberOfLeadingZeros((long)(0xFFFFFFFFFFFFFFFFUL >> i)));
+            }
+
+            Assert.AreEqual(63, Longs.NumberOfLeadingZeros(1L));
+            Assert.AreEqual(64, Longs.NumberOfLeadingZeros(0L));
+        }
+
+        [Test]
+        public void TestNumberOfTrailingZeros()
+        {
+            for (int i = 0; i < 63; ++i)
+            {
+                Assert.AreEqual(i, Longs.NumberOfTrailingZeros(1L << i));
+                Assert.AreEqual(i, Longs.NumberOfTrailingZeros(-1L << i));
+            }
+
+            Assert.AreEqual(63, Longs.NumberOfTrailingZeros(long.MinValue));
+            Assert.AreEqual(64, Longs.NumberOfTrailingZeros(0L));
+        }
+    }
+}