public static void TestCase_AndGateSimulation() { void VerifyStates(Pin x1_out_pin, string x1_out_val, Pin x2_out_pin, string x2_out_val, Pin and_in0_pin, string and_in0_val, Pin and_in1_pin, string and_in1_val, Pin and_out_pin, string and_out_val, Pin y1_in_pin, string y1_in_val, Logic y1_res_real, string y1_res_exp) { Require.That(x1_out_pin.State.Value == Logic.StringToLogicValue(x1_out_val)); Require.That(x2_out_pin.State.Value == Logic.StringToLogicValue(x2_out_val)); Require.That(and_in0_pin.State.Value == Logic.StringToLogicValue(and_in0_val)); Require.That(and_in1_pin.State.Value == Logic.StringToLogicValue(and_in1_val)); Require.That(and_out_pin.State.Value == Logic.StringToLogicValue(and_out_val)); Require.That(y1_in_pin.State.Value == Logic.StringToLogicValue(y1_in_val)); Require.That(y1_res_real.Value == Logic.StringToLogicValue(y1_res_exp)); } Circuit cir = new Circuit(); InTerminal x1 = new InTerminal(); cir.AddElement(x1); InTerminal x2 = new InTerminal(); cir.AddElement(x2); AND and = new AND(); cir.AddElement(and); OutTerminal y1 = new OutTerminal(); cir.AddElement(y1); Pin x1_out = x1.GetPin(PinSide.OUTPUT, 0); Pin x2_out = x2.GetPin(PinSide.OUTPUT, 0); Pin and_in0 = and.GetPin(PinSide.INPUT, 0); Pin and_in1 = and.GetPin(PinSide.INPUT, 1); Pin and_out = and.GetPin(PinSide.OUTPUT, 0); Pin y1_in = y1.GetPin(PinSide.INPUT, 0); cir.Connect(x1_out, and_in0); cir.Connect(x2_out, and_in1); cir.Connect(and_out, y1_in); x1.SimulationInputValue = new Logic(LogicValue.LOGIC_1); x2.SimulationInputValue = new Logic(LogicValue.LOGIC_1); cir.RestartSimulation(); VerifyStates(x1_out, "U", x2_out, "U", and_in0, "U", and_in1, "U", and_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates(x1_out, "1", x2_out, "1", and_in0, "1", and_in1, "1", and_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates(x1_out, "1", x2_out, "1", and_in0, "1", and_in1, "1", and_out, "1", y1_in, "1", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates(x1_out, "1", x2_out, "1", and_in0, "1", and_in1, "1", and_out, "1", y1_in, "1", y1.SimulationResult, "1"); Console.WriteLine("TestCase_AndGateSimulation passed."); }
public static void TestCase_SetNumberOfInputPinsAnd() { Circuit c = new Circuit(); AND and = new AND(); c.AddElement(and); Pin and_in0 = and.GetPin(PinSide.INPUT, 0); Pin and_in1 = and.GetPin(PinSide.INPUT, 1); Require.That(and.GetNumberOfPins(PinSide.INPUT) == 2); Require.That(and.GetNumberOfPins(PinSide.OUTPUT) == 1); InTerminal x1 = new InTerminal(); InTerminal x2 = new InTerminal(); c.AddElement(x1); c.AddElement(x2); Pin x1_out = x1.GetPin(PinSide.OUTPUT, 0); Pin x2_out = x2.GetPin(PinSide.OUTPUT, 0); c.Connect(x1_out, and_in0); Require.That(and_in0.ConnectedPin == x1_out); Require.That(x1_out.ConnectedPin == and_in0); Require.That(and_in1.ConnectedPin == null); c.SetNumberOfInputPins(and, 5); Require.That(and.GetNumberOfPins(PinSide.INPUT) == 5); Require.That(and.GetNumberOfPins(PinSide.OUTPUT) == 1); Require.That(and_in0.ConnectedPin == x1_out); Require.That(x1_out.ConnectedPin == and_in0); for (byte i = 1; i < 5; i++) { Require.That(and.GetPin(PinSide.INPUT, i).ConnectedPin == null); } Pin and_in4 = and.GetPin(PinSide.INPUT, 4); c.Connect(x2_out, and_in4); Require.That(and_in4.ConnectedPin == x2_out); Require.That(x2_out.ConnectedPin == and_in4); c.SetNumberOfInputPins(and, 3); Require.That(and.GetNumberOfPins(PinSide.INPUT) == 3); Require.That(and_in0.ConnectedPin != null); Require.That(x2_out.ConnectedPin == null); for (byte i = 1; i < 3; i++) { Require.That(and.GetPin(PinSide.INPUT, i).ConnectedPin == null); } c.Disconnect(and_in0); Require.That(x1_out.ConnectedPin == null); Require.That(and_in0.ConnectedPin == null); c.RemoveElement(and); Console.WriteLine("TestCase_SetNumberOfInputPinsAnd passed."); }
public static void TestCase_6AndGateSimulation() { void VerifyStates(Pin x1_out_pin, string x1_out_val, Pin x2_out_pin, string x2_out_val, Pin x3_out_pin, string x3_out_val, Pin x4_out_pin, string x4_out_val, Pin x5_out_pin, string x5_out_val, Pin x6_out_pin, string x6_out_val, Pin and_in0_pin, string and_in0_val, Pin and_in1_pin, string and_in1_val, Pin and_in2_pin, string and_in2_val, Pin and_in3_pin, string and_in3_val, Pin and_in4_pin, string and_in4_val, Pin and_in5_pin, string and_in5_val, Pin and_out_pin, string and_out_val, Pin y1_in_pin, string y1_in_val, Logic y1_res_real, string y1_res_exp) { Require.That(x1_out_pin.State.Value == Logic.StringToLogicValue(x1_out_val)); Require.That(x2_out_pin.State.Value == Logic.StringToLogicValue(x2_out_val)); Require.That(x3_out_pin.State.Value == Logic.StringToLogicValue(x3_out_val)); Require.That(x4_out_pin.State.Value == Logic.StringToLogicValue(x4_out_val)); Require.That(x5_out_pin.State.Value == Logic.StringToLogicValue(x5_out_val)); Require.That(x6_out_pin.State.Value == Logic.StringToLogicValue(x6_out_val)); Require.That(and_in0_pin.State.Value == Logic.StringToLogicValue(and_in0_val)); Require.That(and_in1_pin.State.Value == Logic.StringToLogicValue(and_in1_val)); Require.That(and_in2_pin.State.Value == Logic.StringToLogicValue(and_in2_val)); Require.That(and_in3_pin.State.Value == Logic.StringToLogicValue(and_in3_val)); Require.That(and_in4_pin.State.Value == Logic.StringToLogicValue(and_in4_val)); Require.That(and_in5_pin.State.Value == Logic.StringToLogicValue(and_in5_val)); Require.That(and_out_pin.State.Value == Logic.StringToLogicValue(and_out_val)); Require.That(y1_in_pin.State.Value == Logic.StringToLogicValue(y1_in_val)); Require.That(y1_res_real.Value == Logic.StringToLogicValue(y1_res_exp)); } Circuit cir = new Circuit(); InTerminal x1 = new InTerminal(); cir.AddElement(x1); InTerminal x2 = new InTerminal(); cir.AddElement(x2); InTerminal x3 = new InTerminal(); cir.AddElement(x3); InTerminal x4 = new InTerminal(); cir.AddElement(x4); InTerminal x5 = new InTerminal(); cir.AddElement(x5); InTerminal x6 = new InTerminal(); cir.AddElement(x6); AND and = new AND(); cir.AddElement(and); cir.SetNumberOfInputPins(and, 6); for (byte i = 1; i < 6; i++) { Require.That(and.GetPin(PinSide.INPUT, i).ConnectedPin == null); } OutTerminal y1 = new OutTerminal(); cir.AddElement(y1); Pin x1_out = x1.GetPin(PinSide.OUTPUT, 0); Pin x2_out = x2.GetPin(PinSide.OUTPUT, 0); Pin x3_out = x3.GetPin(PinSide.OUTPUT, 0); Pin x4_out = x4.GetPin(PinSide.OUTPUT, 0); Pin x5_out = x5.GetPin(PinSide.OUTPUT, 0); Pin x6_out = x6.GetPin(PinSide.OUTPUT, 0); Pin and_in0 = and.GetPin(PinSide.INPUT, 0); Pin and_in1 = and.GetPin(PinSide.INPUT, 1); Pin and_in2 = and.GetPin(PinSide.INPUT, 2); Pin and_in3 = and.GetPin(PinSide.INPUT, 3); Pin and_in4 = and.GetPin(PinSide.INPUT, 4); Pin and_in5 = and.GetPin(PinSide.INPUT, 5); Pin and_out = and.GetPin(PinSide.OUTPUT, 0); Pin y1_in = y1.GetPin(PinSide.INPUT, 0); cir.Connect(x1_out, and_in0); cir.Connect(x2_out, and_in1); cir.Connect(x3_out, and_in2); cir.Connect(x4_out, and_in3); cir.Connect(x5_out, and_in4); cir.Connect(x6_out, and_in5); cir.Connect(and_out, y1_in); x1.SimulationInputValue = new Logic(LogicValue.LOGIC_1); x2.SimulationInputValue = new Logic(LogicValue.LOGIC_1); x3.SimulationInputValue = new Logic(LogicValue.LOGIC_1); x4.SimulationInputValue = new Logic(LogicValue.LOGIC_1); x5.SimulationInputValue = new Logic(LogicValue.LOGIC_1); x6.SimulationInputValue = new Logic(LogicValue.LOGIC_1); cir.RestartSimulation(); VerifyStates(x1_out, "U", x2_out, "U", x3_out, "U", x4_out, "U", x5_out, "U", x6_out, "U", and_in0, "U", and_in1, "U", and_in2, "U", and_in3, "U", and_in4, "U", and_in5, "U", and_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates(x1_out, "1", x2_out, "1", x3_out, "1", x4_out, "1", x5_out, "1", x6_out, "1", and_in0, "1", and_in1, "1", and_in2, "1", and_in3, "1", and_in4, "1", and_in5, "1", and_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates(x1_out, "1", x2_out, "1", x3_out, "1", x4_out, "1", x5_out, "1", x6_out, "1", and_in0, "1", and_in1, "1", and_in2, "1", and_in3, "1", and_in4, "1", and_in5, "1", and_out, "1", y1_in, "1", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates(x1_out, "1", x2_out, "1", x3_out, "1", x4_out, "1", x5_out, "1", x6_out, "1", and_in0, "1", and_in1, "1", and_in2, "1", and_in3, "1", and_in4, "1", and_in5, "1", and_out, "1", y1_in, "1", y1.SimulationResult, "1"); Console.WriteLine("TestCase_6AndGateSimulation passed."); }
public static void TestCase_Fork_3Not_And_GatesSimulation() { void VerifyStates(Pin x1_out_pin, string x1_out_val, Pin fork_in_pin, string fork_in_val, Pin fork_out0_pin, string fork_out0_val, Pin fork_out1_pin, string fork_out1_val, Pin not0_in_pin, string not0_in_val, Pin not1_in_pin, string not1_in_val, Pin not0_out_pin, string not0_out_val, Pin not1_out_pin, string not1_out_val, Pin and_in0_pin, string and_in0_val, Pin and_in1_pin, string and_in1_val, Pin and_out_pin, string and_out_val, Pin not2_in_pin, string not2_in_val, Pin not2_out_pin, string not2_out_val, Pin y1_in_pin, string y1_in_val, Logic y1_res_real, string y1_res_exp) { Require.That(x1_out_pin.State.Value == Logic.StringToLogicValue(x1_out_val)); Require.That(fork_in_pin.State.Value == Logic.StringToLogicValue(fork_in_val)); Require.That(fork_out0_pin.State.Value == Logic.StringToLogicValue(fork_out0_val)); Require.That(fork_out1_pin.State.Value == Logic.StringToLogicValue(fork_out1_val)); Require.That(not0_in_pin.State.Value == Logic.StringToLogicValue(not0_in_val)); Require.That(not1_in_pin.State.Value == Logic.StringToLogicValue(not1_in_val)); Require.That(not0_out_pin.State.Value == Logic.StringToLogicValue(not0_out_val)); Require.That(not1_out_pin.State.Value == Logic.StringToLogicValue(not1_out_val)); Require.That(and_in0_pin.State.Value == Logic.StringToLogicValue(and_in0_val)); Require.That(and_in1_pin.State.Value == Logic.StringToLogicValue(and_in1_val)); Require.That(and_out_pin.State.Value == Logic.StringToLogicValue(and_out_val)); Require.That(not2_in_pin.State.Value == Logic.StringToLogicValue(not2_in_val)); Require.That(not2_out_pin.State.Value == Logic.StringToLogicValue(not2_out_val)); Require.That(y1_in_pin.State.Value == Logic.StringToLogicValue(y1_in_val)); Require.That(y1_res_real.Value == Logic.StringToLogicValue(y1_res_exp)); } Circuit cir = new Circuit(); InTerminal x1 = new InTerminal(); cir.AddElement(x1); FORK fork = new FORK(); cir.AddElement(fork); AND and = new AND(); cir.AddElement(and); NOT not0 = new NOT(); cir.AddElement(not0); NOT not1 = new NOT(); cir.AddElement(not1); NOT not2 = new NOT(); cir.AddElement(not2); OutTerminal y1 = new OutTerminal(); cir.AddElement(y1); Pin x1_out = x1.GetPin(PinSide.OUTPUT, 0); Pin fork_in = fork.GetPin(PinSide.INPUT, 0); Pin fork_out0 = fork.GetPin(PinSide.OUTPUT, 0); Pin fork_out1 = fork.GetPin(PinSide.OUTPUT, 1); Pin not0_in = not0.GetPin(PinSide.INPUT, 0); Pin not1_in = not1.GetPin(PinSide.INPUT, 0); Pin not0_out = not0.GetPin(PinSide.OUTPUT, 0); Pin not1_out = not1.GetPin(PinSide.OUTPUT, 0); Pin and_in0 = and.GetPin(PinSide.INPUT, 0); Pin and_in1 = and.GetPin(PinSide.INPUT, 1); Pin and_out = and.GetPin(PinSide.OUTPUT, 0); Pin not2_in = not2.GetPin(PinSide.INPUT, 0); Pin not2_out = not2.GetPin(PinSide.OUTPUT, 0); Pin y1_in = y1.GetPin(PinSide.INPUT, 0); cir.Connect(x1_out, fork_in); cir.Connect(fork_out0, not0_in); cir.Connect(fork_out1, not1_in); cir.Connect(not0_out, and_in0); cir.Connect(not1_out, and_in1); cir.Connect(and_out, not2_in); cir.Connect(not2_out, y1_in); x1.SimulationInputValue = new Logic(LogicValue.LOGIC_1); cir.RestartSimulation(); VerifyStates( x1_out, "U", fork_in, "U", fork_out0, "U", fork_out1, "U", not0_in, "U", not0_out, "U", not1_in, "U", not1_out, "U", and_in0, "U", and_in1, "U", and_out, "U", not2_in, "U", not2_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates( x1_out, "1", fork_in, "1", fork_out0, "U", fork_out1, "U", not0_in, "U", not0_out, "U", not1_in, "U", not1_out, "U", and_in0, "U", and_in1, "U", and_out, "U", not2_in, "U", not2_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates( x1_out, "1", fork_in, "1", fork_out0, "1", fork_out1, "1", not0_in, "1", not0_out, "U", not1_in, "1", not1_out, "U", and_in0, "U", and_in1, "U", and_out, "U", not2_in, "U", not2_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates( x1_out, "1", fork_in, "1", fork_out0, "1", fork_out1, "1", not0_in, "1", not0_out, "0", not1_in, "1", not1_out, "0", and_in0, "0", and_in1, "0", and_out, "U", not2_in, "U", not2_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates( x1_out, "1", fork_in, "1", fork_out0, "1", fork_out1, "1", not0_in, "1", not0_out, "0", not1_in, "1", not1_out, "0", and_in0, "0", and_in1, "0", and_out, "0", not2_in, "0", not2_out, "U", y1_in, "U", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates( x1_out, "1", fork_in, "1", fork_out0, "1", fork_out1, "1", not0_in, "1", not0_out, "0", not1_in, "1", not1_out, "0", and_in0, "0", and_in1, "0", and_out, "0", not2_in, "0", not2_out, "1", y1_in, "1", y1.SimulationResult, "U"); cir.NextMoment(); VerifyStates( x1_out, "1", fork_in, "1", fork_out0, "1", fork_out1, "1", not0_in, "1", not0_out, "0", not1_in, "1", not1_out, "0", and_in0, "0", and_in1, "0", and_out, "0", not2_in, "0", not2_out, "1", y1_in, "1", y1.SimulationResult, "1"); Console.WriteLine("TestCase_Fork_3Not_And_GatesSimulation passed."); }