84 lines
2.4 KiB
C#
84 lines
2.4 KiB
C#
using NUnit.Framework;
|
|
|
|
namespace ln.biginteger.test
|
|
{
|
|
public class Tests
|
|
{
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
}
|
|
|
|
[Test]
|
|
public void Test_01_BigInteger()
|
|
{
|
|
Assert.AreEqual(1, BigInteger.Zero.GetLength());
|
|
Assert.AreEqual(1, BigInteger.One.GetLength());
|
|
Assert.AreEqual(2, new BigInteger(long.MaxValue).GetLength());
|
|
Assert.AreEqual(2, new BigInteger(long.MinValue).GetLength());
|
|
Assert.AreEqual(1, new BigInteger((long)1234).GetLength());
|
|
|
|
Assert.AreEqual(BigInteger.One, BigInteger.MinusOne.Twos());
|
|
Assert.AreEqual(BigInteger.MinusOne, BigInteger.One.Twos());
|
|
Assert.AreEqual(BigInteger.Zero, BigInteger.Zero.Twos());
|
|
|
|
Assert.IsTrue(BigInteger.Zero.IsZero);
|
|
Assert.IsFalse(BigInteger.One.IsZero);
|
|
|
|
Assert.AreEqual(BigInteger.One, BigInteger.Zero.Add(BigInteger.One));
|
|
Assert.AreEqual(BigInteger.One, BigInteger.One.Add(BigInteger.Zero));
|
|
Assert.AreNotEqual(BigInteger.Zero, BigInteger.Zero.Add(BigInteger.One));
|
|
|
|
Assert.AreEqual(BigInteger.Zero, BigInteger.One.Sub(BigInteger.One));
|
|
Assert.AreEqual(BigInteger.One, BigInteger.One.Sub(BigInteger.Zero));
|
|
|
|
BigInteger bi5 = new BigInteger(5 << 24);
|
|
BigInteger bi15 = new BigInteger(15 << 24 );
|
|
BigInteger bi75 = new BigInteger(75L << 48 );
|
|
BigInteger bi75b = bi5.Mul(bi15);
|
|
|
|
Assert.AreEqual(bi75, bi75b);
|
|
Assert.AreEqual(new BigInteger(5), bi5 >> 24);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Pass();
|
|
}
|
|
|
|
[Test]
|
|
public void Test_20_Converter()
|
|
{
|
|
foreach (string hexdigits in new string[]{
|
|
"44BBCCDD",
|
|
"FFFFFFFF",
|
|
"1122334455667788",
|
|
"778899AABBCCDDEE"
|
|
})
|
|
TestImplHexConvert(hexdigits);
|
|
}
|
|
|
|
public void TestImplHexConvert(string hexdigits)
|
|
{
|
|
BigInteger bi = BigInteger.FromHexString(hexdigits);
|
|
string rehexed = bi.ToHexString();
|
|
Assert.AreEqual(hexdigits, rehexed);
|
|
}
|
|
|
|
|
|
struct TestVector
|
|
{
|
|
public uint[] a,b,c;
|
|
|
|
public TestVector(uint[] a,uint[] b, uint[] c)
|
|
{
|
|
this.a = a;
|
|
this.b = b;
|
|
this.c = c;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
} |