示例#1
0
        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;
            }
        }
示例#2
0
        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;
            }
        }
示例#3
0
        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;
            }
        }
示例#4
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;
                }
            }
        }