示例#1
0
        public void Solutions_MinusOperator_Test()
        {
            //Try to represent the equation ((5+1) x 3) - 4
            IEquation node1 = new AddOperation(new Integer(5), new Integer(1));
            IEquation node2 = new MultiplyOperation(node1, new Integer(3));
            IEquation equation1 = new MinusOperation(node2, new Integer(4));

            //Try to represent the equation 1 + 2  +3
            IEquation node3 = new AddOperation(new Integer(1), new Integer(2));
            IEquation equation2 = new AddOperation(node3, new Integer(3));

            Solutions solutions = new Solutions();
            solutions.Add(equation1);
            solutions.Add(equation2);

            IEquation equation3 = new Integer(4);

            Solutions new_solutions = solutions - equation3;
            Assert.AreEqual(2, new_solutions.Count);
            Assert.AreEqual(10, new_solutions[0].Value);
            Assert.AreEqual(2, new_solutions[1].Value);

            new_solutions = equation3 - solutions;
            Assert.AreEqual(2, new_solutions.Count);
            Assert.AreEqual(-10, new_solutions[0].Value);
            Assert.AreEqual(-2, new_solutions[1].Value);
        }
示例#2
0
        public void Equation_Test3()
        {
            //Try to represent the equation ((6 / 3) + 2) x 5
            IEquation node1 = new DivideOperation(new Integer(6), new Integer(3));
            Assert.AreEqual(2, node1.Value);

            IEquation node2 = new AddOperation(node1, new Integer(2));
            Assert.AreEqual(4, node2.Value);

            IEquation equation = new MultiplyOperation(node2, new Integer(5));

            Assert.AreEqual(20, equation.Value);
            Assert.AreEqual("((6 / 3) + 2) x 5", equation.ToString());
        }
示例#3
0
        public void Equation_Test1()
        {
            //Try to represent the equation ((5+1) x 3) - 4
            IEquation node1 = new AddOperation(new Integer(5), new Integer(1));
            Assert.AreEqual(6, node1.Value);

            MultiplyOperation node2 = new MultiplyOperation(node1, new Integer(3));
            Assert.AreEqual(18, node2.Value);

            MinusOperation equation = new MinusOperation(node2, new Integer(4));

            Assert.AreEqual(14, equation.Value);
            Assert.AreEqual("((5 + 1) x 3) - 4", equation.ToString());
        }
 public void MultiplyOperation_Test()
 {
     MultiplyOperation op = new MultiplyOperation(new Integer(2), new Integer(4));
     Assert.AreEqual(8, op.Value);
     Assert.AreEqual("2 x 4", op.ToString());
 }