Ejemplo n.º 1
0
        public void DifferentTypes()
        {
            var  poly3 = KtPolynomial.Create(2, 1);
            Term term1 = poly3;
            var  poly1 = KtPolynomial.Create(3, 5, 2, 5);
            var  poly2 = KtPolynomial.Create(3, 12, -2);

            Term term2        = new DiscontinuousTerm(poly1, poly2, Limit.Create(-12, 20));
            var  actualResult = term1 - term2;

            Assert.AreEqual(actualResult.Length, 3);
            Term expectedResult1 = new DiscontinuousTerm(poly3, KtPolynomial.Create(1), ForwardLimit.Create(-12));

            Assert.AreEqual(actualResult[0], expectedResult1);
            Term expectedResult2 = new DiscontinuousTerm((poly3 * poly2) - poly1, poly2, Limit.Create(-12, 20));

            Assert.AreEqual(actualResult[1], expectedResult2);
            Term expectedResult3 = new DiscontinuousTerm(poly3, KtPolynomial.Create(1), BackwardLimit.Create(20));

            Assert.AreEqual(actualResult[2], expectedResult3);
            actualResult = term2 - term1; //reversed
            Assert.AreEqual(actualResult.Length, 3);
            expectedResult1 = new DiscontinuousTerm(-poly3, KtPolynomial.Create(1), ForwardLimit.Create(-12));
            Assert.AreEqual(actualResult[0], expectedResult1);
            expectedResult2 = new DiscontinuousTerm(poly1 - (poly3 * poly2), poly2, Limit.Create(-12, 20));
            Assert.AreEqual(actualResult[1], expectedResult2);
            expectedResult3 = new DiscontinuousTerm(-poly3, KtPolynomial.Create(1), BackwardLimit.Create(20));
            Assert.AreEqual(actualResult[2], expectedResult3);
        }
Ejemplo n.º 2
0
        public void BothDiscontinuousSpliceable()
        {
            var  poly3        = KtPolynomial.Create(2, 1);
            var  poly4        = KtPolynomial.Create(3, 1);
            Term term1        = new DiscontinuousTerm(poly3, poly4, ForwardLimit.Create(9));
            Term term2        = new DiscontinuousTerm(poly3, poly4, BackwardLimit.Create(9));
            var  actualResult = term1 + term2;

            Assert.AreEqual(actualResult.Length, 1);
            Assert.AreEqual(actualResult[0], new ContinuousTerm(poly3, poly4));
        }
Ejemplo n.º 3
0
        public void MultTest()
        {
            var  poly3           = KtPolynomial.Create(2, 1);
            Term term1           = poly3;
            var  poly1           = KtPolynomial.Create(3, 5, 2, 5);
            var  poly2           = KtPolynomial.Create(3, 12, -2);
            Term term2           = new DiscontinuousTerm(poly1, poly2, Limit.Create(-12, 20));
            var  actualResult    = term1 * term2;
            Term expectedResult2 = new DiscontinuousTerm(poly3 * poly1, poly2, Limit.Create(-12, 20));

            Assert.AreEqual(actualResult, expectedResult2);
        }
Ejemplo n.º 4
0
        public void BothDiscontinuousNotTouching()
        {
            var  poly3        = KtPolynomial.Create(2, 1);
            var  poly4        = KtPolynomial.Create(3, 1);
            Term term1        = new DiscontinuousTerm(poly3, poly4, Limit.Create(-12, 9));
            var  poly1        = KtPolynomial.Create(3, 5, 2, 5);
            var  poly2        = KtPolynomial.Create(3, 12, -2);
            Term term2        = new DiscontinuousTerm(poly1, poly2, Limit.Create(10, 20));
            var  actualResult = term1 + term2;

            Assert.AreEqual(actualResult.Length, 2);
            Assert.AreEqual(actualResult[0], term1);
            Assert.AreEqual(actualResult[1], term2);
        }
Ejemplo n.º 5
0
        public void Subtracting()
        {
            var  poly1      = KtPolynomial.Create(4, 0, -2, 0, 4, 1);
            var  poly2      = KtPolynomial.Create(3, -4.3, 1);
            var  poly3      = KtPolynomial.Create(4, 3, 7);
            var  denom      = KtPolynomial.Create(1);
            var  term1      = new DiscontinuousTerm(poly1, denom, Limit.Create(-20, -10));
            var  term2      = new DiscontinuousTerm(poly2, denom, Limit.Create(-15, -5));
            Term term3      = poly3;
            var  expression = new Expression(term1, term3, term2);
            var  actual     = expression - expression;

            _ = new Zero();
            var expected = new Expression((Number)0);

            Assert.AreEqual(actual, expected);
        }
Ejemplo n.º 6
0
        public void BothDiscontinuousBarelyInclusive()
        {
            var  poly3        = KtPolynomial.Create(2, 1);
            var  poly4        = KtPolynomial.Create(3, 1);
            Term term1        = new DiscontinuousTerm(poly3, poly4, Limit.Create(-12, 10));
            var  poly1        = KtPolynomial.Create(3, 5, 2, 5);
            var  poly2        = KtPolynomial.Create(3, 12, -2);
            Term term2        = new DiscontinuousTerm(poly1, poly2, Limit.Create(-12, 20));
            var  actualResult = term1 - term2;

            Assert.AreEqual(actualResult.Length, 2);
            Term expectedResult2 = new DiscontinuousTerm((poly3 * poly2) - (poly1 * poly4), poly4 * poly2, Limit.Create(-12, 10));

            Assert.AreEqual(actualResult[0], expectedResult2);
            Term expectedResult3 = new DiscontinuousTerm(-poly1, poly2, Limit.Create(10, 20));

            Assert.AreEqual(actualResult[1], expectedResult3);
        }
Ejemplo n.º 7
0
        public void Adding()
        {
            var  poly1      = KtPolynomial.Create(4, 0, -2, 0, 4, 1);
            var  poly2      = KtPolynomial.Create(3, -4.3, 1);
            var  poly3      = KtPolynomial.Create(4, 3, 7);
            var  denom      = KtPolynomial.Create(1);
            var  term1      = new DiscontinuousTerm(poly1, denom, Limit.Create(-20, -10));
            var  term2      = new DiscontinuousTerm(poly2, denom, Limit.Create(-15, -5));
            Term term3      = poly3;
            var  expression = new Expression(term1, term3, term2);
            var  expected   = new Expression(
                new DiscontinuousTerm(2 * poly3, denom, ForwardLimit.Create(-20)),
                new DiscontinuousTerm(2 * (poly3 + poly1), denom, Limit.Create(-20, -15)),
                new DiscontinuousTerm(2 * (poly3 + poly1 + poly2), denom, Limit.Create(-15, -10)),
                new DiscontinuousTerm(2 * (poly3 + poly2), denom, Limit.Create(-10, -5)),
                new DiscontinuousTerm(2 * poly3, denom, BackwardLimit.Create(-5)));

            Assert.AreEqual(expression + expression, expected);
        }
Ejemplo n.º 8
0
        public void BothDiscontinuousOverlap()
        {
            var  poly3        = KtPolynomial.Create(2, 1);
            var  poly4        = KtPolynomial.Create(3, 1);
            Term term1        = new DiscontinuousTerm(poly3, poly4, Limit.Create(-12, 15));
            var  poly1        = KtPolynomial.Create(3, 5, 2, 5);
            var  poly2        = KtPolynomial.Create(3, 12, -2);
            Term term2        = new DiscontinuousTerm(poly1, poly2, Limit.Create(10, 20));
            var  actualResult = term1 + term2;

            Assert.AreEqual(actualResult.Length, 3);
            Term term3 = new DiscontinuousTerm(poly3, poly4, Limit.Create(-12, 10));
            Term term4 = new DiscontinuousTerm((poly3 * poly2) + (poly1 * poly4), poly4 * poly2, Limit.Create(10, 15));
            Term term5 = new DiscontinuousTerm(poly1, poly2, Limit.Create(15, 20));

            Assert.AreEqual(actualResult[0], term3);
            Assert.AreEqual(actualResult[1], term4);
            Assert.AreEqual(actualResult[2], term5);
        }
Ejemplo n.º 9
0
        public void ContinuousAndNot()
        {
            var  poly3        = KtPolynomial.Create(2, 1);
            Term term1        = poly3;
            var  poly1        = KtPolynomial.Create(3, 5, 2, 5);
            var  poly2        = KtPolynomial.Create(3, 12, -2);
            Term term2        = new DiscontinuousTerm(poly1, poly2, Limit.Create(-12, 20));
            var  actualResult = term1 + term2;

            Assert.AreEqual(actualResult.Length, 3);
            Term expectedResult1 = new DiscontinuousTerm(poly3, KtPolynomial.Create(1), ForwardLimit.Create(-12));

            Assert.AreEqual(actualResult[0], expectedResult1);
            Term expectedResult2 = new DiscontinuousTerm((poly3 * poly2) + poly1, poly2, Limit.Create(-12, 20));

            Assert.AreEqual(actualResult[1], expectedResult2);
            Term expectedResult3 = new DiscontinuousTerm(poly3, KtPolynomial.Create(1), BackwardLimit.Create(20));

            Assert.AreEqual(actualResult[2], expectedResult3);
            Assert.IsTrue(actualResult.SequenceEqual(term2 + term1));
        }