public void CreateChildrenTest()
        {
            //GateNode node1 = new GateNode("A'");
            //GateNode node2 = new GateNode("(A+B)'");
            //GateNode node3 = new GateNode("(A+B) + C'");
            //GateNode node4 = new GateNode("(A+C)'+B");
            GateNode node5 = new GateNode("D*(A+C*B)'+B+C");

            Dictionary <String, List <VariableNode> > variables = new Dictionary <string, List <VariableNode> >();

            //variables = node1.CreateChildren(variables);
            //BooleanNode.PrintTree(node1);
            //foreach (var variable in variables.Keys)
            //{
            //    Console.WriteLine(variable);
            //}

            variables = new Dictionary <string, List <VariableNode> >();
            variables = node5.CreateChildren(variables);
            BooleanNode.PrintTree(node5);
            foreach (var variable in variables.Keys)
            {
                Console.WriteLine(variable);
            }
        }
        public void SplitTest()
        {
            GateNode node1 = new GateNode("A'");
            GateNode node2 = new GateNode("(A+B)'");
            GateNode node3 = new GateNode("A+B");
            GateNode node4 = new GateNode("(A+C)'+B");
            GateNode node5 = new GateNode("(A+C)'+B+C");

            Tuple <String, String> expressions1 = node1.CreateChildrenExpressions();

            Assert.AreEqual("A", expressions1.Item1);
            Assert.AreEqual("SingleInv", expressions1.Item2);

            Tuple <String, String> expressions2 = node2.CreateChildrenExpressions();

            Assert.AreEqual("A+B", expressions2.Item1);
            Assert.AreEqual("MultiInv", expressions2.Item2);

            Tuple <String, String> expressions3 = node3.CreateChildrenExpressions();

            Assert.AreEqual("A", expressions3.Item1);
            Assert.AreEqual("B", expressions3.Item2);

            Tuple <String, String> expressions4 = node4.CreateChildrenExpressions();

            Assert.AreEqual("(A+C)'", expressions4.Item1);
            Assert.AreEqual("B", expressions4.Item2);

            Tuple <String, String> expressions5 = node5.CreateChildrenExpressions();

            Assert.AreEqual("(A+C)'", expressions5.Item1);
            Assert.AreEqual("B+C", expressions5.Item2);
        }
Example #3
0
    public void OnMouseUp()
    {
        RaycastHit hitInfo = new RaycastHit();
        bool       hit     = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);

        if (hit)
        {
            clickedObject = hitInfo.transform.gameObject;
            node          = clickedObject.GetComponent <GateNode>();
            if (line == null)
            {
                line = this.gameObject.AddComponent <LineRenderer>();
                line.SetWidth(0.1F, .1F);
                line.SetVertexCount(2);
                line.material.color = Color.white;
            }
        }

        if (status)
        {
            status = false;
        }
        else
        {
            status = true;
        }
    }
        public void IsInvertedTest()
        {
            GateNode node1 = new GateNode("A'");
            GateNode node2 = new GateNode("(A+B)'");
            GateNode node3 = new GateNode("(A+B)");
            GateNode node4 = new GateNode("(A+C)'+B"); // should be false as the whole expression isn't inverted, just a sub piece


            Assert.IsTrue(node1.CheckIfInverted());
            Assert.IsTrue(node2.CheckIfInverted());
            Assert.IsFalse(node3.CheckIfInverted());
            Assert.IsFalse(node4.CheckIfInverted());
        }
        public void FindSplitTest()
        {
            GateNode node1 = new GateNode("(A*B)");
            GateNode node2 = new GateNode("A+BC");
            GateNode node3 = new GateNode("(A+B)*C");
            GateNode node4 = new GateNode("(A+C)'+B");
            GateNode node5 = new GateNode("(A+C)'+B+C");

            Assert.AreEqual(1, node1.findSplitPoint()); // 1 is expected becuase it should trim down the parenthesis
            Assert.AreEqual(1, node2.findSplitPoint());
            Assert.AreEqual(5, node3.findSplitPoint());
            Assert.AreEqual(6, node4.findSplitPoint());
            Assert.AreEqual(6, node5.findSplitPoint());
        }
        //Create one gate node
        private void CreateGateNode(int nodeId, Random r, int containerId)
        {
            GateNode gateNodeObj = new GateNode();

            gateNodeObj.NodeId = nodeId;
            //generate Random NodeStatus number 1 or 2 (Left or Right)
            gateNodeObj.NodeStatus       = Convert.ToByte((r.Next(1, 400) % Two) + 1);
            gateNodeObj.ParentGateNodeId = Convert.ToInt32(nodeId / Two);
            gateNodeObj.containerId      = containerId;
            //Adding binary children of the GateNode
            if (nodeId * Two <= _totalNodesToCreate)
            {
                gateNodeObj.AddChild(nodeId * Two);
                gateNodeObj.AddChild((nodeId * Two) + 1);
            }
            _bTreeGateNodes.Add(gateNodeObj);
        }
Example #7
0
 // Update is called once per frame
 void Update()
 {
     if (line && node)
     {
         line.SetPosition(0, gameObject.transform.position);
         line.SetPosition(1, node.transform.position);
     }
     if (node)
     {
         status = node.status;
     }
     if (SteamVR_Actions.default_GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) && e.bHit)
     {
         down = e.target.gameObject;
     }
     if (SteamVR_Actions.default_GrabPinch.GetStateUp(SteamVR_Input_Sources.Any) && e.bHit)
     {
         up = e.target.gameObject;
         if (up && down)
         {
             if (down.GetInstanceID() == up.GetInstanceID())
             {
                 status = !status;
             }
             else if (down.tag != "InputNode")
             {
                 node = down.GetComponent <GateNode>();
                 if (line == null)
                 {
                     line = this.gameObject.AddComponent <LineRenderer>();
                     line.SetWidth(0.1F, .1F);
                     line.SetVertexCount(2);
                     line.material.color = Color.white;
                 }
                 else
                 {
                     Destroy(gameObject.GetComponent <LineRenderer>());
                     node = null;
                 }
                 down = null;
                 up   = null;
             }
         }
     }
 }