Exemple #1
0
        public void DivTest()
        {
            foreach (var prime in _primes)
            {
                var firstPoly  = GeneratePoly(40, prime);
                var secondPoly = GeneratePoly(30, prime);

                var polyMath = new PolynomialMath(prime);


                while (secondPoly.Deg == -1)
                {
                    secondPoly = GeneratePoly(30, prime);
                }

                var res = polyMath.Div(firstPoly, secondPoly);
                var rem = polyMath.Rem(firstPoly, secondPoly);


                var checkPoly = polyMath.Add(rem, polyMath.Mul(secondPoly, res));
                for (int i = 0; i <= firstPoly.Deg; i++)
                {
                    if ((firstPoly[i] + prime * prime) % prime != (checkPoly[i] + prime * prime) % prime)
                    {
                        throw new Exception();
                    }
                }
            }
        }
Exemple #2
0
        public void AddTest()
        {
            foreach (var prime in _primes)
            {
                var firstPoly  = GeneratePoly(20, prime);
                var secondPoly = GeneratePoly(30, prime);


                var polyMath = new PolynomialMath(prime);

                Polynomial res;
                res = polyMath.Add(firstPoly, secondPoly);

                var checkPoly = polyMath.Sub(res, secondPoly);

                for (int i = 0; i <= firstPoly.Deg; i++)
                {
                    if ((firstPoly[i] + prime * prime) % prime != (checkPoly[i] + prime * prime) % prime)
                    {
                        throw new Exception();
                    }
                }
            }
        }