Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        public void TestFullAdderDiscreets()
        {
            List<SimulatedComponent> components = new List<SimulatedComponent>();

            // bit 1 stage.
            XOrGate xogResultStage = new XOrGate();
            AndGate agResultStage1 = new AndGate();
            XOrGate xogInputStage1 = new XOrGate();
            AndGate agInputStage1 = new AndGate();

            OrGate carryOut1 = new OrGate();

            Connector inputA1 = new Connector();
            Connector inputB1 = new Connector();
            Connector outputCarryOut1 = new Connector();
            Connector outputSumOut1 = new Connector();
            Connector internalSumToB1 = new Connector();
            Connector internalCarry1a = new Connector();
            Connector internalCarry1b = new Connector();


            xogInputStage1.ConnectInputB(internalSumToB1);
            xogInputStage1.ConnectOutput(outputSumOut1);
            agInputStage1.ConnectInputB(internalSumToB1);
            agInputStage1.ConnectOutput(internalCarry1a);

            xogResultStage.ConnectInputA(inputA1);
            xogResultStage.ConnectInputB(inputB1);
            xogResultStage.ConnectOutput(internalSumToB1);
            agResultStage1.ConnectInputA(inputA1);
            agResultStage1.ConnectInputB(inputB1);
            agResultStage1.ConnectOutput(internalCarry1b);

            carryOut1.ConnectInputA(internalCarry1a);
            carryOut1.ConnectInputB(internalCarry1b);
            carryOut1.ConnectOutput(outputCarryOut1);

            components.Add(xogResultStage);
            components.Add(agResultStage1);
            components.Add(xogInputStage1);
            components.Add(agInputStage1);
            components.Add(carryOut1);

            // bit 2 stage.
            XOrGate xogResultStage2 = new XOrGate();
            AndGate agResultStage2 = new AndGate();
            XOrGate xogInputStage2 = new XOrGate();
            AndGate agInputStage2 = new AndGate();
            OrGate carryOut2 = new OrGate();

            Connector inputA2 = new Connector();
            Connector inputB2 = new Connector();
            Connector outputCarryOut2 = new Connector();
            Connector outputSumOut2 = new Connector();
            Connector internalSumToB2 = new Connector();
            Connector internalCarry2a = new Connector();
            Connector internalCarry2b = new Connector();

            xogInputStage2.ConnectInputA(outputCarryOut1);
            xogInputStage2.ConnectInputB(internalSumToB2);
            xogInputStage2.ConnectOutput(outputSumOut2);
            agInputStage2.ConnectInputA(outputCarryOut1);
            agInputStage2.ConnectInputB(internalSumToB2);
            agInputStage2.ConnectOutput(internalCarry2a);

            xogResultStage2.ConnectInputA(inputA2);
            xogResultStage2.ConnectInputB(inputB2);
            xogResultStage2.ConnectOutput(internalSumToB2);
            agResultStage2.ConnectInputA(inputA2);
            agResultStage2.ConnectInputB(inputB2);
            agResultStage2.ConnectOutput(internalCarry2b);

            carryOut2.ConnectInputA(internalCarry2a);
            carryOut2.ConnectInputB(internalCarry2b);
            carryOut2.ConnectOutput(outputCarryOut2);

            components.Add(xogResultStage2);
            components.Add(agResultStage2);
            components.Add(xogInputStage2);
            components.Add(agInputStage2);
            components.Add(carryOut2);

            // bit 3 stage.
            XOrGate xogResultStage3 = new XOrGate();
            AndGate agResultStage3 = new AndGate();
            XOrGate xogInputStage3 = new XOrGate();
            AndGate agInputStage3 = new AndGate();
            OrGate carryOut3 = new OrGate();

            Connector inputA3 = new Connector();
            Connector inputB3 = new Connector();
            Connector outputCarryOut3 = new Connector();
            Connector outputSumOut3 = new Connector();
            Connector internalSumToB3 = new Connector();
            Connector internalCarry3a = new Connector();
            Connector internalCarry3b = new Connector();

            xogInputStage3.ConnectInputA(outputCarryOut2);
            xogInputStage3.ConnectInputB(internalSumToB3);
            xogInputStage3.ConnectOutput(outputSumOut3);
            agInputStage3.ConnectInputA(outputCarryOut2);
            agInputStage3.ConnectInputB(internalSumToB3);
            agInputStage3.ConnectOutput(internalCarry3a);

            xogResultStage3.ConnectInputA(inputA3);
            xogResultStage3.ConnectInputB(inputB3);
            xogResultStage3.ConnectOutput(internalSumToB3);
            agResultStage3.ConnectInputA(inputA3);
            agResultStage3.ConnectInputB(inputB3);
            agResultStage3.ConnectOutput(internalCarry3b);

            carryOut3.ConnectInputA(internalCarry3a);
            carryOut3.ConnectInputB(internalCarry3b);
            carryOut3.ConnectOutput(outputCarryOut3);

            components.Add(xogResultStage3);
            components.Add(agResultStage3);
            components.Add(xogInputStage3);
            components.Add(agInputStage3);
            components.Add(carryOut3);


            for(int y = 0; y < 8; y++)
            for (int x = 0; x < 8; x ++)
            {
                if ((y & 1) != 0)
                {
                    inputB1.SendSignal(true);
                }
                else
                {
                    inputB1.SendSignal(false);
                }
                if ((y & 2) != 0)
                {
                    inputB2.SendSignal(true);
                }
                else
                {
                    inputB2.SendSignal(false);
                }
                if ((y & 4) != 0)
                {
                    inputB3.SendSignal(true);
                }
                else
                {
                    inputB3.SendSignal(false);
                }

                if ((x & 1) != 0)
                {
                    inputA1.SendSignal(true);
                }
                else
                {
                    inputA1.SendSignal(false);
                }
                if ((x & 2) != 0)
                {
                    inputA2.SendSignal(true);
                }
                else
                {
                    inputA2.SendSignal(false);
                }
                if ((x & 4) != 0)
                {
                    inputA3.SendSignal(true);
                }
                else
                {
                    inputA3.SendSignal(false);
                }


                for (int z = 0; z < 3; z++)
                {
                    foreach (SimulatedComponent sc in components)
                    {
                        sc.Tick();
                    }
                }
                int result = 0;

                if (outputCarryOut3.HasSignal())
                {
                    result |= 8;
                }

                if (outputSumOut3.HasSignal())
                {
                    result |= 4;
                }

                if (outputSumOut2.HasSignal())
                {
                    result |= 2;
                }

                if (outputSumOut1.HasSignal())
                {
                    result |= 1;
                }

                Assert.AreEqual(x + y, result);
                Console.WriteLine("x[" + x.ToString() + "] y[" + y.ToString() + "] = Result[" + result.ToString() + "]");

            }
        }
Ejemplo n.º 3
0
        public void TestAndGateNoOutput()
        {
            List<SimulatedComponent> components = new List<SimulatedComponent>();

            AndGate ag = new AndGate();

            Connector inputConnectorA = new Connector();
            ag.ConnectInputA(inputConnectorA);
            Connector inputConnectorB = new Connector();
            ag.ConnectInputB(inputConnectorB);

            components.Add(ag);

            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;
                }
            }
        }
Ejemplo n.º 4
0
        public void TestAndGateAllConnectorsGood()
        {
            List<SimulatedComponent> components = new List<SimulatedComponent>();

            AndGate ag = new AndGate();

            Connector inputConnectorA = new Connector();
            ag.ConnectInputA(inputConnectorA);
            Connector inputConnectorB = new Connector();
            ag.ConnectInputB(inputConnectorB);

            Connector outputConnector = new Connector();
            ag.ConnectOutput(outputConnector);


            components.Add(ag);

            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;
                }
            }
        }