Пример #1
0
        public void TryModuloInvertFail2Test()
        {
            BigUInt bui     = new BigUInt("DEADBEEF");
            BigUInt mod     = new BigUInt("BEEF");
            BigUInt inverse = new BigUInt();

            // Should fail when biguint is bigger than modulus
            Assert.IsFalse(mod.IsZero);
            Utilities.AssertThrows <ArgumentException>(() => bui.TryModuloInvert(mod, inverse));
        }
Пример #2
0
        public void TryModuloInvertFail1Test()
        {
            BigUInt bui     = new BigUInt("DEADBEEF");
            BigUInt mod     = new BigUInt();
            BigUInt inverse = new BigUInt();

            // Should fail when modulus is zero
            Assert.IsTrue(mod.IsZero);
            Utilities.AssertThrows <ArgumentException>(() => bui.TryModuloInvert(mod, inverse));
        }
Пример #3
0
        public void TryModuloInvertFail2Test()
        {
            BigUInt bui     = new BigUInt("DEADBEEF");
            BigUInt mod     = new BigUInt("BEEF");
            BigUInt inverse = new BigUInt();

            // Should fail when biguint is bigger than modulus
            Assert.IsFalse(mod.IsZero);
            bui.TryModuloInvert(mod, inverse);
        }
Пример #4
0
        public void TryModuloInvertFail1Test()
        {
            BigUInt bui     = new BigUInt("DEADBEEF");
            BigUInt mod     = new BigUInt();
            BigUInt inverse = new BigUInt();

            // Should fail when modulus is zero
            Assert.IsTrue(mod.IsZero);
            bui.TryModuloInvert(mod, inverse);
        }
Пример #5
0
        public void TryModuloInvertTest()
        {
            BigUInt bui      = new BigUInt(bitCount: 64, value: 12);
            BigUInt mod      = new BigUInt(bitCount: 64, value: 25);
            BigUInt inverse1 = new BigUInt();
            BigUInt inverse2 = new BigUInt();

            Assert.IsTrue(bui.TryModuloInvert(mod, inverse1));

            Assert.AreEqual(23ul, inverse1.Data(0));

            Assert.IsTrue(bui.TryModuloInvert(modulus: 25ul, inverse: inverse2));

            Assert.AreEqual(23ul, inverse2.Data(0));

            // Should fail (but not throw) when biguint value and modulus are not coprime
            BigUInt bui2 = new BigUInt(bitCount: 64, value: 12);
            BigUInt mod2 = new BigUInt(bitCount: 64, value: 24);

            Assert.IsFalse(mod2.IsZero);
            Assert.IsFalse(bui2.IsZero);

            Assert.IsFalse(bui2.TryModuloInvert(mod2, inverse1));
        }
Пример #6
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; });
        }