예제 #1
0
        public void PolynomGcd_Test()
        {
            var _rational = new Rational();
            var _input    = new List <Tuple <PolynomR, 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 });
            var _gcd1     = new PolynomR(_rational, new Q[] { 1, -1, 0, 1 });

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

            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 });
            var _gcd2 = new PolynomR(_rational, new Q[] { 1 });

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

            foreach (var t in _input)
            {
                Assert.AreEqual(t.Item3, PolynomR.GetGcd(t.Item1, t.Item2),
                                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 });
            var _gcd3 = new Polynom <long, ZnRing>(_GF2, new long[] { 1 });

            Assert.AreEqual(_gcd3, Polynom <long, ZnRing> .GetGcd(_p31, _p32),
                            String.Format("Input: ({0}); ({1})", _p31, _p32));
        }