Example #1
0
        private List <Node> CreateNode(MathematicNode node, JSONNode creatorNode)
        {
            node.Equation = equations[creatorNode.equation];
            List <MathematicNode> matNodes  = new List <MathematicNode>();
            List <LeafNode>       leafNodes = new List <LeafNode>();

            for (int i = 0; i < creatorNode.children.Length; i++)
            {
                if (creatorNode.children[i].children != null && creatorNode.children[i].children.Length > 0)
                {
                    MathematicNode mathematicNode = new MathematicNode();
                    mathematicNode.SetParent(node);
                    mathematicNode.SetChildren(CreateNode(mathematicNode, creatorNode.children[i]));
                    matNodes.Add(mathematicNode);
                }
                else
                {
                    LeafNode leafNode = new LeafNode();
                    leafNode.Setup(node);
                    leafNode.SetExpectedValue(creatorNode.children[i].value);
                    leafNodes.Add(leafNode);
                }
            }

            List <Node> result = new List <Node>();

            result.AddRange(matNodes);
            result.AddRange(leafNodes);
            return(result);
        }
Example #2
0
        public void GetTreeRoot_Test()
        {
            RootNode root = service.GetTreeRoot(node) as RootNode;

            Assert.AreEqual(8, root.Value);
            Assert.NotNull((root as RootNode).Child);

            MathematicNode matNode = (root as RootNode).Child as MathematicNode;

            Assert.IsInstanceOf <Sum>(matNode.Equation);
            Assert.AreEqual(2, matNode.Children.Count);

            LeafNode leaf = matNode.Children[1] as LeafNode;

            Assert.AreEqual(2, leaf.ExpectedValue);

            MathematicNode matNode2 = matNode.Children[0] as MathematicNode;

            Assert.IsInstanceOf <Multiplication>(matNode2.Equation);
            Assert.AreEqual(2, matNode2.Children.Count);

            LeafNode leaf1 = matNode2.Children[0] as LeafNode;

            Assert.AreEqual(2, leaf1.ExpectedValue);

            LeafNode leaf2 = matNode2.Children[1] as LeafNode;

            Assert.AreEqual(3, leaf2.ExpectedValue);
        }
Example #3
0
        public AbstractNode GetTreeRoot(JSONNode node)
        {
            RootNode       rootNode       = new RootNode();
            MathematicNode mathematicNode = new MathematicNode();

            rootNode.Setup(mathematicNode, node.value);
            mathematicNode.SetParent(rootNode);
            mathematicNode.SetChildren(CreateNode(mathematicNode, node.children[0]));
            return(rootNode);
        }