Exemple #1
0
        public void SetValueTwice_NamedVariable_ReturnsSecondVal()
        {
            SillyParser p = new SillyParser(null);
            Leaf        n = (Leaf)p.m("a");

            p.SetVar("a", 2);
            Assert.AreEqual(2, n.Eval());
            p.SetVar("a", 3);
            Assert.AreEqual(3, n.Eval());
        }
Exemple #2
0
        public void Simplify_NamedVariableWithVal_ReturnsVal()
        {
            SillyParser p = new SillyParser(null);
            Leaf        n = (Leaf)p.m("a");

            p.SetVar("a", 2);
            Assert.AreEqual(2, n.Eval());
        }
Exemple #3
0
        public void Simplify_NegativeNegations_success()
        {
            SillyParser p       = new SillyParser(null);
            Unary       node    = (Unary)p.m("-", p.m("a"));
            Unary       neg     = (Unary)node.Negate();
            Leaf        negSimp = (Leaf)neg.Simplify();

            Assert.AreEqual("--a", neg.Unparse());
            Assert.AreEqual("a", negSimp.Unparse());
            p.SetVar("a", 2);
            Assert.AreEqual(-2, node.Eval());
            Assert.AreEqual(2, neg.Eval());
            Assert.AreEqual(2, negSimp.Eval());
        }
Exemple #4
0
        public void IntermediateHomogeneousTransformationsTest()
        {
            SillyParser            p     = (SillyParser)SillyParser.GetInstance();
            DenavitHartenbergTable table = new DenavitHartenbergTable(p.InterpretMatrix(
                                                                          $"0,  0,         d1,  th1;" +
                                                                          $"0,  1.5*PI,  d2,  1.5*PI;" +
                                                                          $"0,  0,         d3,  0.5*PI"));

            Matrix A_0_1 = p.InterpretMatrix(
                "cos(th1), -sin(th1), 0, 0;" +
                "sin(th1), cos(th1),  0, 0;" +
                "0,        0,         1, d1;" +
                "0,        0,         0, 1").Simplify();
            Matrix A_1_2 = p.InterpretMatrix(
                "0,  0,  1, 0;" +
                "-1, 0,  0, 0;" +
                "0,  -1, 0, d2;" +
                "0,  0,  0, 1").Simplify();
            Matrix A_2_3 = p.InterpretMatrix(
                "0, -1, 0, 0;" +
                "1, 0,  0, 0;" +
                "0, 0,  1, d3;" +
                "0, 0,  0, 1").Simplify();

            p.SetVar("PI", Math.PI);

            HomogeneousTransformation[] HTs = table.IntermediateHomogeneousTransformations();
            Matrix[] HTMs = new Matrix[HTs.Length];
            for (int i = 0; i < HTs.Length; i++)
            {
                HTMs[i] = new Matrix(HTs[i].SubMatrix(0, 4, 0, 4));
                HTMs[i] = HTMs[i].Simplify();
            }
            Assert.AreEqual(A_0_1, HTMs[0], $"Expected \n{A_0_1.PrettyPrint()}\nbut was\n{HTMs[0].PrettyPrint()}");
            Assert.AreEqual(A_1_2, HTMs[1], $"Expected \n{A_1_2.PrettyPrint()}\nbut was\n{HTMs[1].PrettyPrint()}");
            Assert.AreEqual(A_2_3, HTMs[2], $"Expected \n{A_2_3.PrettyPrint()}\nbut was\n{HTMs[2].PrettyPrint()}");
        }