Exemplo n.º 1
0
        public void GcdLcm1()
        {
            BigInteger _4611686016279904256 = ParseBigInt("4611686016279904256");

            Assert((int)Integer.Gcd(-1, -1) == 1 && (int)Integer.Lcm(-1, -1) == 1);
            Assert((int)Integer.Gcd(0, -1) == 1 && (int)Integer.Lcm(0, -1) == 0);
            Assert((int)Integer.Gcd(-1, 0) == 1 && (int)Integer.Lcm(-1, 0) == 0);
            Assert((int)Integer.Gcd(0, 0) == 0 && (int)Integer.Lcm(0, 0) == 0);
            Assert((int)Integer.Gcd((BigInteger)0, 0) == 0 && (int)Integer.Lcm((BigInteger)0, 0) == 0);

            Assert((int)Integer.Gcd(Int32.MaxValue, Int32.MinValue) == 1);
            Assert((BigInteger)Integer.Lcm(Int32.MaxValue, Int32.MinValue) == _4611686016279904256);

            Assert((int)Integer.Gcd(Int32.MinValue, Int32.MaxValue) == 1);
            Assert((BigInteger)Integer.Lcm(Int32.MinValue, Int32.MaxValue) == _4611686016279904256);

            Assert((BigInteger)Integer.Gcd(Int32.MinValue, Int32.MinValue) == -(BigInteger)Int32.MinValue);
            Assert((BigInteger)Integer.Lcm(Int32.MinValue, Int32.MinValue) == -(BigInteger)Int32.MinValue);

            Assert((int)Integer.Gcd(Int32.MaxValue, Int32.MaxValue) == Int32.MaxValue);
            Assert((int)Integer.Lcm(Int32.MaxValue, Int32.MaxValue) == Int32.MaxValue);

            Assert((int)Integer.Gcd(Int32.MaxValue, -1) == 1);
            Assert((int)Integer.Lcm(Int32.MaxValue, -1) == Int32.MaxValue);

            Assert((int)Integer.Gcd(Int32.MinValue, -1) == 1);
            Assert((BigInteger)Integer.Lcm(Int32.MinValue, -1) == -(BigInteger)Int32.MinValue);
        }
Exemplo n.º 2
0
        public void Gcd(Integer left, Integer right, Integer expected)
        {
            using (Immutability.Guard(left, right))
            {
                var actual = left.Gcd(right);

                Assert.Equal(expected, actual);
            }
        }
Exemplo n.º 3
0
        public void ModInv(Integer value, Integer modulus)
        {
            using (Immutability.Guard(value, modulus))
            {
                var result = value.ModInv(modulus);

                var common = value.Gcd(modulus);
                if (value % modulus != 0 && common == 1)
                {
                    var check = (value * result) % modulus;

                    Assert.Equal(1, check);
                }
                else
                {
                    Assert.Equal(0, result);
                }
            }
        }