예제 #1
0
        public void ModuloInvertTest()
        {
            BigUInt bui = new BigUInt(bitCount: 64, value: 12);
            BigUInt mod = new BigUInt(bitCount: 64, value: 25);

            BigUInt inverse1 = bui.ModuloInvert(mod);

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

            BigUInt inverse2 = bui.ModuloInvert(modulus: 25ul);

            Assert.AreEqual(23ul, inverse2.Data(0));
        }
예제 #2
0
        public void ModuloInvertFail3Test()
        {
            // Should fail when biguint value and modulus are not coprime
            BigUInt bui = new BigUInt(bitCount: 64, value: 12);
            BigUInt mod = new BigUInt(bitCount: 64, value: 24);

            Assert.IsFalse(mod.IsZero);
            Assert.IsFalse(bui.IsZero);

            Utilities.AssertThrows <ArgumentException>(() => bui.ModuloInvert(mod));
        }
예제 #3
0
        public void ModuloInvertFail2Test()
        {
            // Should fail when modulus is not greater than the BigUInt value
            BigUInt bui = new BigUInt("DEADBEEF");
            BigUInt mod = new BigUInt("BEEF");

            Assert.IsFalse(mod.IsZero);
            Assert.IsFalse(bui.IsZero);

            Utilities.AssertThrows <ArgumentException>(() => bui.ModuloInvert(mod));
        }
예제 #4
0
        public void ModuloInvertFail1Test()
        {
            // Should fail when modulus is zero
            BigUInt bui = new BigUInt("DEADBEEF");
            BigUInt mod = new BigUInt();

            Assert.IsTrue(mod.IsZero);
            Assert.IsFalse(bui.IsZero);

            Utilities.AssertThrows <ArgumentException>(() => bui.ModuloInvert(mod));
        }
예제 #5
0
        public void ModuloInvertFail3Test()
        {
            // Should fail when biguint value and modulus are not coprime
            BigUInt bui = new BigUInt(bitCount: 64, value: 12);
            BigUInt mod = new BigUInt(bitCount: 64, value: 24);

            Assert.IsFalse(mod.IsZero);
            Assert.IsFalse(bui.IsZero);

            BigUInt result = bui.ModuloInvert(mod);
        }
예제 #6
0
        public void ModuloInvertFail2Test()
        {
            // Should fail when modulus is not greater than the BigUInt value
            BigUInt bui = new BigUInt("DEADBEEF");
            BigUInt mod = new BigUInt("BEEF");

            Assert.IsFalse(mod.IsZero);
            Assert.IsFalse(bui.IsZero);

            BigUInt result = bui.ModuloInvert(mod);
        }
예제 #7
0
        public void ModuloInvertFail1Test()
        {
            // Should fail when modulus is zero
            BigUInt bui = new BigUInt("DEADBEEF");
            BigUInt mod = new BigUInt();

            Assert.IsTrue(mod.IsZero);
            Assert.IsFalse(bui.IsZero);

            BigUInt result = bui.ModuloInvert(mod);
        }
예제 #8
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; });
        }