Exemplo n.º 1
0
        public void ParseTest_Success3()
        {
            //arrange
            CPolynomial expected = new CPolynomial(new Complex[] { 0, 2 });

            //action
            CPolynomial actual = CPolynomial.Parse("2x");

            //assert
            actual.Should().Be(expected);
        }
Exemplo n.º 2
0
        public void ParseTest_Success5()
        {
            //arrange
            CPolynomial expected = new CPolynomial(new Complex[] { 3, new Complex(-4, 12.3), 1 });

            //action
            CPolynomial actual = CPolynomial.Parse("x+3 + x^2-(5-12.3i)*x");

            //assert
            actual.Should().Be(expected);
        }
Exemplo n.º 3
0
        public void ParseTest_Success2()
        {
            //arrange
            CPolynomial expected = new CPolynomial(new Complex[] { new Complex(0, -0.3) });

            //action
            CPolynomial actual = CPolynomial.Parse("-0.3i");

            //assert
            actual.Should().Be(expected);
        }
Exemplo n.º 4
0
        public void SecondDerivativeTest_Analytical()
        {
            //arrange
            CPolynomial target   = new CPolynomial(new Complex[] { 5, 8, -14, 3, 6, -22 });
            CPolynomial expected = new CPolynomial(new Complex[] { -28, 18, 72, -440 });

            //action
            CPolynomial actual = target.SecondDerivative();

            //assert
            actual.Should().Be(expected);
        }
Exemplo n.º 5
0
        public void FirstDerivativeTest_Analytical()
        {
            //arrange
            CPolynomial target   = new CPolynomial(new Complex[] { 5, 8, -14, 3, 6, -22 });
            CPolynomial expected = new CPolynomial(new Complex[] { 8, -28, 9, 24, -110 });

            //action
            CPolynomial actual = target.FirstDerivative();

            //assert
            actual.Should().Be(expected);
        }
Exemplo n.º 6
0
        public void AntiderivativeTest()
        {
            //arrange
            CPolynomial target   = new CPolynomial(new Complex[] { 3, 8, 16 });
            CPolynomial expected = new CPolynomial(new Complex[] { 0, 3, 4, 16.0 / 3 });

            //action
            CPolynomial actual = target.Antiderivative();

            //assert
            actual.Should().Be(expected);
        }
Exemplo n.º 7
0
        public void NthDerivativeTest_Analytical()
        {
            //arrange
            CPolynomial target   = new CPolynomial(new Complex[] { 5, 8, -14, 3, 6, -22 });
            CPolynomial expected = new CPolynomial(new Complex[] { 18, 144, -1320 });

            //action
            CPolynomial actual = target.NthDerivative(3);

            //assert
            actual.Should().Be(expected);
        }
Exemplo n.º 8
0
        public void DivBinomTest()
        {
            //arrange
            double      TOL = 1E-10;
            CPolynomial f = new CPolynomial(new Complex[] { 3, 0.2, new Complex(3, 8.2), -0.16, new Complex(2.3, 2), 0, 18.3466, 2000 });
            Complex     c = 346.34645;
            Complex     r, rtest;

            //action
            CPolynomial q = CPolynomial.DivBinom(f, c, out r);

            f[0] -= r;
            CPolynomial qtest = CPolynomial.DivBinom(f, c, out rtest);

            //assert
            Complex.Abs(rtest).Should().BeLessOrEqualTo(TOL);
            q.Should().Be(qtest);
        }
Exemplo n.º 9
0
        public void DivTest()
        {
            //arrange
            double TOL = 1E-12;

            CPolynomial f    = new CPolynomial(new Complex[] { new Complex(3467.2, 456), new Complex(2.225, -0.0123), new Complex(46.2, 4.24), new Complex(2, 2), new Complex(12.8, 16.3), new Complex(0, 0), new Complex(22, 347) });
            CPolynomial g    = new CPolynomial(new Complex[] { new Complex(3, 8.5), new Complex(11, -0.5), new Complex(0, 1), new Complex(1, 2), new Complex(346, 4.365) });
            CPolynomial zero = new CPolynomial(1);

            CPolynomial r;
            CPolynomial q     = CPolynomial.Divide(f, g, out r);
            CPolynomial rtest = new CPolynomial(1);

            //action
            CPolynomial qtest = CPolynomial.Divide(f - r, g, out rtest);

            //assert
            for (int j = 0; j < rtest.Length; j++)
            {
                Complex.Abs(rtest[j]).Should().BeLessOrEqualTo(TOL);
            }
            qtest.Should().Be(q);
        }