Example #1
0
        public void DivideRemainderTest()
        {
            BigUInt bui       = new BigUInt("DEADBEEF");
            BigUInt op        = new BigUInt("BEEF");
            BigUInt remainder = new BigUInt();

            BigUInt result = bui.DivideRemainder(op, remainder);

            Assert.AreEqual(1ul, result.UInt64Count);
            Assert.AreEqual(0x12a90ul, result.Data(0));
            Assert.AreEqual(1ul, remainder.UInt64Count);
            Assert.AreEqual(0x227Ful, remainder.Data(0));

            BigUInt result2 = bui.DivideRemainder(0xDEADul, remainder);

            Assert.AreEqual(1ul, result2.UInt64Count);
            Assert.AreEqual(0x10000ul, result2.Data(0));
            Assert.AreEqual(1ul, remainder.UInt64Count);
            Assert.AreEqual(0xBEEFul, remainder.Data(0));
        }
Example #2
0
 BigUInt Reminder(BigUInt n1, BigUInt n2, BigUInt res)
 {
     using (var v = n1.DivideRemainder(n2, res))
         return(res);
 }
Example #3
0
        public void ExceptionsTest()
        {
            BigUInt bui  = new BigUInt("DEADBEEF");
            BigUInt bui1 = null;

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = new BigUInt((BigUInt)null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = new BigUInt((string)null));
            Utilities.AssertThrows <ArgumentException>(() => bui1     = new BigUInt(bitCount: -1));
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = new BigUInt(bitCount: 64, hexString: null));
            Utilities.AssertThrows <ArgumentException>(() => bui1     = new BigUInt(bitCount: -1, hexString: "ABCDEF"));
            Utilities.AssertThrows <ArgumentException>(() => bui1     = new BigUInt(bitCount: -1, value: 10ul));

            bui1 = new BigUInt();
            BigUInt bui2 = new BigUInt();

            Utilities.AssertThrows <ArgumentOutOfRangeException>(() => bui.Data(1));

            Utilities.AssertThrows <ArgumentOutOfRangeException>(() => bui[5]);
            Utilities.AssertThrows <ArgumentOutOfRangeException>(() => bui[5] = 2);

            Utilities.AssertThrows <ArgumentNullException>(() => bui.DivideRemainder(bui1, null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.DivideRemainder(null, bui2));
            Utilities.AssertThrows <ArgumentException>(() => bui.DivideRemainder(bui1, bui2));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.DivideRemainder(1ul, null));
            Utilities.AssertThrows <ArgumentException>(() => bui.DivideRemainder(0ul, bui2));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.DuplicateFrom(null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.DuplicateTo(null));

            Assert.IsFalse(bui.Equals(null));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.Load(null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.ModuloInvert(null));
            Utilities.AssertThrows <ArgumentException>(() => bui.Resize(bitCount: -1));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.Save(null));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.Set((BigUInt)null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.Set((string)null));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.TryModuloInvert(bui1, null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.TryModuloInvert(null, bui2));
            Utilities.AssertThrows <ArgumentException>(() => bui.TryModuloInvert(bui1, bui2));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.TryModuloInvert(1ul, null));

            bui2 = null;

            Utilities.AssertThrows <ArgumentNullException>(() => bui2 = +bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2 = -bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2 = ~bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2++);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2--);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui + bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 + bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 + 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui - bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 - bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 - 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui * bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 * bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 * 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui / bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 / bui);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui / bui1);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 / 1ul);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui / 0ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui ^ bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 ^ bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 ^ 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui & bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 & bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 & 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui | bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 | bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 | 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 << 5);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui1 << -1);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 >> 5);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui1 >> -1);

            Utilities.AssertThrows <ArgumentNullException>(() => { double d = (double)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { float f = (float)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { ulong u = (ulong)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { long l = (long)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { uint u = (uint)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { int i = (int)bui2; });
        }