Ejemplo n.º 1
0
        public void PolynomGcdEx_Test()
        {
            var _rational = new Rational();
            var _input    = new List <Tuple <PolynomR, PolynomR> >();
            var _p11      = new PolynomR(_rational, new Q[] { -5, 8, -3, -4, 2, 0, 1 });
            var _p12      = new PolynomR(_rational, new Q[] { 1, -1, 1, 0, 0, 1 });

            _input.Add(new Tuple <PolynomR, PolynomR>(_p11, _p12));

            var _p21 = new PolynomR(_rational, new Q[] { 1, 1, 0, 1, 0, 1 });
            var _p22 = new PolynomR(_rational, new Q[] { 1, 0, 0, 0, 1 });

            _input.Add(new Tuple <PolynomR, PolynomR>(_p21, _p22));

            foreach (var t in _input)
            {
                PolynomR a, b;
                var      _gcd = PolynomR.GetGcdEx(t.Item1, t.Item2, out a, out b);
                var      _sum = t.Item1 * a + t.Item2 * b;
                Assert.AreEqual(_gcd, _sum, String.Format("Input: ({0}); ({1})", t.Item1, t.Item2));
            }

            var _GF2 = new ZnRing(2);
            var _p31 = new Polynom <long, ZnRing>(_GF2, new long[] { 1, 1, 0, 0, 0, 1 });
            var _p32 = new Polynom <long, ZnRing>(_GF2, new long[] { 1, 0, 0, 1, 1 });

            Polynom <long, ZnRing> a3, b3;
            var _gcd3 = Polynom <long, ZnRing> .GetGcdEx(_p31, _p32, out a3, out b3);

            Assert.AreEqual(_gcd3, _p31 * a3 + _p32 * b3, String.Format("Input: ({0}); ({1})", _p31, _p32));
        }