public void HalfAdderTest() { Connector inputA_connector = new Connector(); Connector inputB_connector = new Connector(); Connector sum_connector = new Connector(); Connector carry_connector = new Connector(); HalfAdder ha = new HalfAdder(); TestOutput tstOutSum = new TestOutput(); TestOutput tstOutCarry = new TestOutput(); ha.AddConnector_A(inputA_connector); ha.AddConnector_B(inputB_connector); ha.AddConnector_Sum(sum_connector); ha.AddConnector_Carry(carry_connector); tstOutSum.AddConnector_A(sum_connector); tstOutCarry.AddConnector_A(carry_connector); //false,false A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //false,true A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,false A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,true A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsTrue(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //false,false B,A tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //false,true B,A tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,false B,A tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,true B,A tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsTrue(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); }
public void FullAdderTest() { Connector inputA_connector = new Connector(); Connector inputB_connector = new Connector(); Connector inputCarry_connector = new Connector(); Connector lowerSum_to_UpperB_connector = new Connector(); Connector upperCarry_to_OrA_connector = new Connector(); Connector lowerCarry_to_OrB_connector = new Connector(); Connector sum_connector = new Connector(); Connector carry_connector = new Connector(); HalfAdder haLower = new HalfAdder(); HalfAdder haUpper = new HalfAdder(); TwoInputGate orGate = new OrGate(); TestOutput tstOutSum = new TestOutput(); TestOutput tstOutCarry = new TestOutput(); // all direct inputs. haLower.AddConnector_A(inputA_connector); haLower.AddConnector_B(inputB_connector); haUpper.AddConnector_A(inputCarry_connector); // lower sum to upper B haLower.AddConnector_Sum(lowerSum_to_UpperB_connector); haUpper.AddConnector_B(lowerSum_to_UpperB_connector); // lower Carry to orB haLower.AddConnector_Carry(lowerCarry_to_OrB_connector); orGate.AddConnector_B(lowerCarry_to_OrB_connector); // upper Carry to orA haUpper.AddConnector_Carry(upperCarry_to_OrA_connector); orGate.AddConnector_A(upperCarry_to_OrA_connector); haUpper.AddConnector_Sum(sum_connector); tstOutSum.AddConnector_A(sum_connector); orGate.AddConnector_Out(carry_connector); tstOutCarry.AddConnector_A(carry_connector); //false,false,false A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //false,false,true A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(false); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //false,true,false A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(false); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //false,true,true A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsTrue(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,false,false A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(true); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,false,true A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsTrue(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,true,false A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(false); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsTrue(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); //true,true,true A,B tstOutSum.ResetResult(); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); tstOutCarry.ResetResult(); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputA_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputB_connector.SetSignal(true); Assert.IsFalse(tstOutSum.Result); Assert.IsFalse(tstOutSum.Triggered); Assert.IsFalse(tstOutCarry.Result); Assert.IsFalse(tstOutCarry.Triggered); inputCarry_connector.SetSignal(true); Assert.IsTrue(tstOutSum.Result); Assert.IsTrue(tstOutSum.Triggered); Assert.IsTrue(tstOutCarry.Result); Assert.IsTrue(tstOutCarry.Triggered); }