Ejemplo n.º 1
0
        public void perfect_gate_logic_test(double input1, double input2, double expectedOutput)
        {
            var xorGate = new XorGate(TTLGateTypeEnum.Perfect, 2);

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

            var result = xorGate.Output(0);

            Assert.Equal(expectedOutput, result);
        }
Ejemplo n.º 2
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)}");
            }
        }