Esempio n. 1
0
        public void TestHandleNegative()
        {
            Node and = new And();

            and.AddDefaultInputs("IN", true);
            and.AddDefaultInputs("IN2", false);
            and.SetDefaultInputs();

            and.Handle();

            Assert.IsFalse(and.Output);
        }
Esempio n. 2
0
        public void TestNotCompletedLoop()
        {
            /** Basic circuit **/
            //Adder
            Node node1 = new Or()
            {
                Name = "Or 1"
            };
            Node node2 = new Or()
            {
                Name = "Or 2"
            };

            Node node3 = new Not()
            {
                Name = "Not 3"
            };
            Node node4 = new Not()
            {
                Name = "Not 4"
            };

            Node node5 = new And()
            {
                Name = "And 5"
            };
            Node node6 = new And()
            {
                Name = "And 6"
            };

            bool s = true;
            bool r = false;

            //Edges
            node5.AddDefaultInputs("IN1", s); //input 1
            node6.AddDefaultInputs("IN2", s);

            node5.AddDefaultInputs("IN3", r);
            node6.AddDefaultInputs("IN4", r);


            node1.AddOutput(node3);
            node2.AddOutput(node4);
            node3.AddOutput(node2);
            node4.AddOutput(node1);
            node5.AddOutput(node1);
            node6.AddOutput(node2);


            Circuit circuit = new Circuit()
            {
                Name = "Circuit 1"
            };

            circuit.Components.Add(node1);
            circuit.Components.Add(node2);
            circuit.Components.Add(node3);
            circuit.Components.Add(node4);
            circuit.Components.Add(node5);
            circuit.Components.Add(node6);

            circuit.Run(new Validator());

            foreach (Component comp in circuit.Components)
            {
                if (comp.ClassType != "Circuit" && !comp.Resolved)
                {
                    throw new Exception("Circuit not completed: " + comp.Name);
                }
            }
        }