public void TestNotGateBothConnectorsGood() { List<SimulatedComponent> components = new List<SimulatedComponent>(); NotGate ng = new NotGate(); Connector inputConnector = new Connector(); ng.ConnectInputA(inputConnector); Connector outputConnector = new Connector(); ng.ConnectOutput(outputConnector); components.Add(ng); bool currSignal = false; for (int x = 1; x < 30; x++) { inputConnector.SendSignal(currSignal); foreach (SimulatedComponent sc in components) { sc.Tick(); } Assert.IsTrue(outputConnector.HasSignal() == (! currSignal)); currSignal = !currSignal; } }
public void TestNotGateNoInput() { List<SimulatedComponent> components = new List<SimulatedComponent>(); NotGate ng = new NotGate(); Connector outputConnector = new Connector(); ng.ConnectOutput(outputConnector); components.Add(ng); bool currSignal = false; for (int x = 1; x < 30; x++) { foreach (SimulatedComponent sc in components) { sc.Tick(); } // floating input is 'false' Assert.IsTrue(outputConnector.HasSignal()); currSignal = !currSignal; } }
public void TestNotGateNoOutput() { List<SimulatedComponent> components = new List<SimulatedComponent>(); NotGate ng = new NotGate(); Connector inputConnector = new Connector(); ng.ConnectInputA(inputConnector); components.Add(ng); bool currSignal = false; for (int x = 1; x < 30; x++) { inputConnector.SendSignal(currSignal); foreach (SimulatedComponent sc in components) { sc.Tick(); } currSignal = !currSignal; } }
public void TestBuiltUpNAndGateNoOutput() { List<SimulatedComponent> components = new List<SimulatedComponent>(); AndGate ag = new AndGate(); NotGate ng = new NotGate(); Connector inputConnectorA = new Connector(); ag.ConnectInputA(inputConnectorA); Connector inputConnectorB = new Connector(); ag.ConnectInputB(inputConnectorB); // put a not gate on the output of the and gate.. Connector andToNot = new Connector(); ag.ConnectOutput(andToNot); ng.ConnectInputA(andToNot); // out of the not gate.. Connector outputConnector = new Connector(); ng.ConnectOutput(outputConnector); // ordering here is important for signal propogation.. if we reverse the order the propogation will be delayed.. components.Add(ag); components.Add(ng); 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; } } }