public void IsNotValidWithTwoInputsAndOutput() { not.AddOutput(GetBusInstance()); not.AddInput(GetBusInstance()); not.AddInput(GetBusInstance()); Assert.IsTrue(not.IsValid()); }
public void TestInfiniteLoop() { /** Basic circuit **/ //Adder Node not1 = new Not() { Name = "Not 1" }; Node or1 = new Or() { Name = "Or 1" }; Node and1 = new And() { Name = "And 1" }; Node nor1 = new Nor() { Name = "Nor 1" }; bool input1 = true; bool input2 = false; //Edges not1.AddDefaultInputs("IN1", input1); //input 1 or1.AddDefaultInputs("IN1", input1); or1.AddDefaultInputs("IN2", input2); //endpoint AND not1.AddOutput(and1); or1.AddOutput(and1); //endpoint NOR not1.AddOutput(nor1); or1.AddOutput(nor1); //create infinite loop or1.OutputList.Add(new Edge(or1, not1)); Circuit circuit = new Circuit() { Name = "Circuit 1" }; circuit.Components.Add(not1); circuit.Components.Add(or1); circuit.Components.Add(and1); circuit.Components.Add(nor1); circuit.Run(new Validator()); }
public void TestAddOutput() { Node from = new Not(); Node to = new Not(); from.AddOutput(to); Assert.AreEqual(to.NrOfInputs, 1); Assert.AreEqual(from.OutputList[0].Out, to); }
private void btnSimulate2_Click(object sender, EventArgs e) { InputUnit input1 = new InputUnit(); InputUnit input2 = new InputUnit(); Or gate1 = new Or(); Not gate2 = new Not(); OutputUnit output = new OutputUnit(); Bus bus1 = new Bus(input1, gate1); Bus bus2 = new Bus(input2, gate1); Bus bus3 = new Bus(gate1, gate2); Bus bus4 = new Bus(gate2, output); gate1.AddInput(bus1, bus2); gate2.AddInput(bus3); gate1.AddOutput(bus3); gate2.AddOutput(bus4); input1.AddOutput(bus1); input2.AddOutput(bus2); output.AddInput(bus4); Circuit circuit = new Circuit(); circuit.AddGates(gate1, gate2, input1, input2, output); circuit.AddBuses(bus1, bus2, bus3, bus4); if (circuit.IsValid()) { circuit.Simulate(); if (output.currentState == 1) { picOutput2.ImageLocation = @"..\..\src\GUI\Images\OnBulb.jpg"; } else { picOutput2.ImageLocation = @"..\..\src\GUI\Images\OffBulb.jpg"; } } else { picOutput2.ImageLocation = @"..\..\src\GUI\Images\InvalidCircuit.png"; } }
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); } } }