public void Parse_1()
        {
            string str = "cos(x)*(e^(3+7x)-2e^(2x))";

            var result = StringToSummand.Parse(str);

            result.Should().HaveCount(1);
            result[0].PolynomialDegree.Should().Be(0);
            result[0].Coefficient.Should().Be(1.0);
            result[0].Multiplicands.Should().HaveCount(1);
            result[0].Multiplicands[0].Should()
            .Match <Cosine>(
                x =>
                MathHelper.AreApproximatelyEqual(x.Aparam, 1.0) &&
                MathHelper.AreApproximatelyEqual(x.Bparam, 0.0));

            result[0].SumsRaisedToPower.Should().HaveCount(1);
            result[0].SumsRaisedToPower[0].Degree.Should().Be(1);
            var sum = result[0].SumsRaisedToPower[0].Sum;

            sum.Should().HaveCount(2);

            sum[0].PolynomialDegree.Should().Be(0);
            sum[0].Coefficient.Should().Be(1.0);
            sum[0].Multiplicands.Should().HaveCount(1);
            sum[0].Multiplicands[0].Should()
            .Match <ExponentialFunction>(
                x =>
                MathHelper.AreApproximatelyEqual(x.Aparam, 7.0) &&
                MathHelper.AreApproximatelyEqual(x.Bparam, 3.0));


            sum[1].PolynomialDegree.Should().Be(0);
            sum[1].Coefficient.Should().Be(-2);
            sum[1].Multiplicands.Should().HaveCount(1);
            sum[1].Multiplicands[0].Should()
            .Match <ExponentialFunction>(
                x =>
                MathHelper.AreApproximatelyEqual(x.Aparam, 2.0) &&
                MathHelper.AreApproximatelyEqual(x.Bparam, 0.0));
        }
        public void Parse_6()
        {
            string str = "x^(2/3)";

            var a = StringToSummand.FindPolynomialDegree("x^(2/3)");

            var result = StringToSummand.Parse(str);

            result.Should().HaveCount(1);
            result[0].PolynomialDegree.Should().Be(0);
            result[0].Coefficient.Should().Be(1.0);
            result[0].Multiplicands.Should().HaveCount(1);
            result[0].Multiplicands[0].Should()
            .Match <PowerFunction>(
                x =>
                MathHelper.AreApproximatelyEqual(x.Aparam, 1.0) &&
                MathHelper.AreApproximatelyEqual(x.Bparam, 0.0) &&
                x.PowerNumerator == 2 &&
                x.PowerDenominator == 3);

            result[0].SumsRaisedToPower.Should().HaveCount(0);
        }
Esempio n. 3
0
        // (lim x->0) sin (x + 3) = sin(3) ~ 0.141120008059867
        public void CalculateLimit_AndReturnsCorrectLimit_5()
        {
            var numerator = new List <Summand>
            {
                new Summand
                {
                    Coefficient   = 1.0,
                    Multiplicands = new List <IElementaryFunction>
                    {
                        new Sine()
                        {
                            Aparam = 1.0,
                            Bparam = 3
                        }
                    }
                }
            };

            var denominator = new List <Summand>
            {
                new Summand
                {
                    Coefficient = 1.0
                }
            };

            var normalizedFunction = new NormalizedFunction
            {
                Numerator   = numerator,
                Denominator = denominator
            };

            var result = LimitCalculator.CalculateLimit(normalizedFunction, 0);

            result.LimitResultType.Should().Be(LimitResultType.RealNumber);
            MathHelper.AreApproximatelyEqual(result.Value, 0.141, 0.005).Should().BeTrue();
        }