示例#1
0
        public void OrGateTest()
        {
            TestOutput tstOut = new TestOutput();
            Connector inputA_connector = new Connector();
            Connector inputB_connector = new Connector();
            Connector gate_out_to_class = new Connector();

            TwoInputGate gate = new OrGate();

            //inputs
            gate.AddConnector_A(inputA_connector);
            gate.AddConnector_B(inputB_connector);

            //outputs
            tstOut.AddConnector_A(gate_out_to_class);
            gate.AddConnector_Out(gate_out_to_class);

            //false,false A,B
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(false);

            Assert.IsFalse(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);

            inputB_connector.SetSignal(false);

            Assert.IsFalse(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);

            //false,false B,A
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputB_connector.SetSignal(false);

            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(false);

            Assert.IsFalse(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);

            // false, true A,B
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(false);

            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputB_connector.SetSignal(true);

            Assert.IsTrue(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);

            //false,true B,A
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputB_connector.SetSignal(true);

            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(false);

            Assert.IsTrue(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);

            // true,false A,B
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(true);

            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputB_connector.SetSignal(false);

            Assert.IsTrue(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);

            //false,true B,A
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputB_connector.SetSignal(false);

            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(true);

            Assert.IsTrue(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);


            // true,true A,B
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(true);

            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputB_connector.SetSignal(true);

            Assert.IsTrue(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);

            //true,true B,A
            tstOut.ResetResult();
            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputB_connector.SetSignal(true);

            Assert.IsFalse(tstOut.Result);
            Assert.IsFalse(tstOut.Triggered);

            inputA_connector.SetSignal(true);

            Assert.IsTrue(tstOut.Result);
            Assert.IsTrue(tstOut.Triggered);
        }
示例#2
0
        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);


        }