示例#1
0
        public void test_one_input_and_gate(int input, int output)
        {
            var andGate = new AndGate(TTLGateTypeEnum.Perfect, 1);

            andGate.Inputs[0].InputSample.Add(new InputSignal {
                Timing = 0, Voltage = input, Unknown = false
            });

            Assert.Equal(output, andGate.Output(0));
        }
示例#2
0
        public void ttl_and_gate_logic_tests(double input1, double input2, double expectedOutput)
        {
            var andGate = new AndGate(TTLGateTypeEnum.Perfect, 2);

            andGate.Inputs[0].InputSample.Add(new InputSignal {
                Timing = 0, Voltage = input1, Unknown = false
            });
            andGate.Inputs[1].InputSample.Add(new InputSignal {
                Timing = 0, Voltage = input2, Unknown = false
            });

            Assert.Equal(expectedOutput, andGate.Output(0));
        }
示例#3
0
        public void test_two_inputs_one_inverted(double input1, double input2, double expectedOutput)
        {
            // input 2 is inverted
            var andGate = new AndGate(TTLGateTypeEnum.Perfect, 2);

            andGate.Inputs[0].InputSample.Add(new InputSignal {
                Timing = 0, Voltage = input1, Unknown = false
            });
            andGate.Inputs[1].InputSample.Add(new InputSignal {
                Timing = 0, Voltage = input2, Unknown = false
            });
            andGate.Inputs[1].InputInverted = true;

            Assert.Equal(expectedOutput, andGate.Output(0));
        }
示例#4
0
        //  can be removed; just trying out stuff
        public void BasicComposite_NoBuilders()
        {
            var notGate = new NotGate();

            notGate.SetInput(Generator.AnInactiveSignal());

            var orGate = new OrGate();

            orGate.AddInput(Generator.AnInactiveSignal());
            orGate.AddInput(Generator.AnActiveSignal());

            var andGate = new AndGate();

            andGate.AddInput(notGate);
            andGate.AddInput(orGate);

            Assert.True(andGate.Output());
        }
示例#5
0
        static void HalfAdderTest()
        {
            var signalGenerator1 = new SignalGenerator();
            var signalGenerator2 = new SignalGenerator();

            bool signalHigh     = true;
            bool longSignalHigh = true;

            for (int i = 0; i < 200; i++)
            {
                if (i % 20 == 0)
                {
                    signalHigh = !signalHigh;
                }

                if (i % 40 == 0)
                {
                    longSignalHigh = !longSignalHigh;
                }

                signalGenerator1.AddSample(signalHigh ? 5 : 0);
                signalGenerator2.AddSample(longSignalHigh ? 5 : 0);
            }

            var xorGate = new XorGate(TTLGateTypeEnum.Normal, 2);
            var andGate = new AndGate(TTLGateTypeEnum.Normal, 2);

            var circuit = new Circuit();

            circuit.Gates.Add(xorGate);
            circuit.Gates.Add(andGate);
            circuit.Gates.Add(signalGenerator1);
            circuit.Gates.Add(signalGenerator2);

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator1,
                Termination = xorGate.Inputs[0]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator2,
                Termination = xorGate.Inputs[1]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator1,
                Termination = andGate.Inputs[0]
            });

            circuit.Connections.Add(new Connection
            {
                Source      = signalGenerator2,
                Termination = andGate.Inputs[1]
            });

            circuit.RunCircuit();

            for (int i = 0; i < 200; i++)
            {
                _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)}  S:{xorGate.Output(i)}  C:{andGate.Output(i)}");
            }
        }