public void TestNOrGateAllConnectorsGood() { List<SimulatedComponent> components = new List<SimulatedComponent>(); NOrGate og = new NOrGate(); Connector inputConnectorA = new Connector(); og.ConnectInputA(inputConnectorA); Connector inputConnectorB = new Connector(); og.ConnectInputB(inputConnectorB); Connector outputConnector = new Connector(); og.ConnectOutput(outputConnector); components.Add(og); bool currSignal1 = false; bool currSignal2 = false; for (int x = 1; x < 30; x++) { inputConnectorA.SendSignal(currSignal1); inputConnectorB.SendSignal(currSignal2); foreach (SimulatedComponent sc in components) { sc.Tick(); } Console.WriteLine("Signal1[" + currSignal1.ToString() + "] Signal2[" + currSignal2.ToString() + "] = Result[" + outputConnector.HasSignal().ToString() + "]"); Assert.IsTrue(outputConnector.HasSignal() == (! (currSignal1 || currSignal2))); currSignal1 = !currSignal1; if (currSignal1 == false) { currSignal2 = !currSignal2; } } }
public void TestNOrGateNoOutput() { List<SimulatedComponent> components = new List<SimulatedComponent>(); NOrGate og = new NOrGate(); Connector inputConnectorA = new Connector(); og.ConnectInputA(inputConnectorA); Connector inputConnectorB = new Connector(); og.ConnectInputB(inputConnectorB); components.Add(og); bool currSignal1 = false; bool currSignal2 = false; for (int x = 1; x < 30; x++) { inputConnectorA.SendSignal(currSignal1); inputConnectorB.SendSignal(currSignal2); foreach (SimulatedComponent sc in components) { sc.Tick(); } Console.WriteLine("Signal1[" + currSignal1.ToString() + "] Signal2[" + currSignal2.ToString() + "]"); currSignal1 = !currSignal1; if (currSignal1 == false) { currSignal2 = !currSignal2; } } }
public void TestLatchAllConnectorsGood() { List<SimulatedComponent> components = new List<SimulatedComponent>(); NOrGate og1 = new NOrGate(); NOrGate og2 = new NOrGate(); Connector R = new Connector(); Connector S = new Connector(); Connector Q = new Connector(); Connector NOT_Q = new Connector(); og1.ConnectInputA(R); og1.ConnectOutput(Q); og2.ConnectInputB(S); og2.ConnectOutput(NOT_Q); // cross connect for latch behavior og1.ConnectInputB(NOT_Q); og2.ConnectInputA(Q); components.Add(og1); components.Add(og2); for (int x = 1; x < 30; x++) { if (x == 4 || x == 12 || x == 20 || x == 28) { Console.WriteLine("Strobing Reset"); R.SendSignal(true); } else { R.SendSignal(false); } if (x == 8 || x == 16 || x == 24) { Console.WriteLine("Strobing Set"); S.SendSignal(true); } else { S.SendSignal(false); } foreach (SimulatedComponent sc in components) { sc.Tick(); } Console.WriteLine("Q[" + Q.HasSignal().ToString() + "] NOT_Q[" + NOT_Q.HasSignal().ToString() + "]"); } }