コード例 #1
0
        public void Write_HighPosEdge_Low()
        {
            var uut    = new NorGate();
            var input1 = uut.AddInput().CreateConnection();
            var input2 = uut.AddInput().CreateConnection();
            var output = uut.Output.CreateConnection();

            input1.Write(DigitalLevel.High);
            input2.Write(DigitalLevel.PosEdge);

            uut.Output.Level.Should().Be(DigitalLevel.Low);
        }
コード例 #2
0
        public void Result_AtLeastOneInputTrue_ShouldReturnFalse()
        {
            // Arrange
            NorGate Gate = new NorGate();

            Gate.In = new INode[] { LowStartPoint, HighStartPoint };

            // Act
            bool output = Gate.Result();

            // Assert
            Assert.IsFalse(output);
        }
コード例 #3
0
        public void Result_AllInputsFalse_ShouldReturnTrue()
        {
            // Arrange
            NorGate Gate = new NorGate();

            Gate.In = new INode[] { LowStartPoint, LowStartPoint };

            // Act
            bool output = Gate.Result();

            // Assert
            Assert.IsTrue(output);
        }
コード例 #4
0
ファイル: NorGateTests.cs プロジェクト: fdecaire/LogicLibrary
        public void perfect_gate_logic_test(double input1, double input2, double expectedOutput)
        {
            var norGate = new NorGate(TTLGateTypeEnum.Perfect, 2);

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

            var result = norGate.Output(0);

            Assert.Equal(expectedOutput, result);
        }
コード例 #5
0
    private LightComponent duplicateAt(Type type, Vector2Int position, int rotation, bool flipped)
    {
        //makes a duplicate of the component passed in

        LightComponent result = null;

        if (type == typeof(AndGate))
        {
            result = new AndGate(position, rotation, flipped);
        }
        else if (type == typeof(OrGate))
        {
            result = new OrGate(position, rotation, flipped);
        }
        else if (type == typeof(NotGate))
        {
            result = new NotGate(position, rotation, flipped);
        }
        else if (type == typeof(BufferGate))
        {
            result = new BufferGate(position, rotation, flipped);
        }
        else if (type == typeof(NandGate))
        {
            result = new NandGate(position, rotation, flipped);
        }
        else if (type == typeof(XorGate))
        {
            result = new XorGate(position, rotation, flipped);
        }
        else if (type == typeof(XnorGate))
        {
            result = new XnorGate(position, rotation, flipped);
        }
        else if (type == typeof(NorGate))
        {
            result = new NorGate(position, rotation, flipped);
        }
        else if (type == typeof(Splitter))
        {
            result = new Splitter(position, rotation, flipped);
        }
        else if (type == typeof(Reflector))
        {
            result = new Reflector(position, rotation, flipped);
        }
        else if (type == typeof(GraphOutput))
        {
            result = new GraphOutput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND));
        }
        else if (type == typeof(GraphInput))
        {
            result = new GraphInput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE));
        }
        else
        {
            throw new System.Exception(type + " was not found when selecting the from the logic graph editor");
        }

        return(result);
    }
コード例 #6
0
        public static DigitalLogicDiagram GetTestDigitalLogicDiagram2(IScheduler scheduler)
        {
            // SR NOR latch
            // SR latch operation
            // S	R	Action
            // 0	0	No Change
            // 0	1	Q = 0
            // 1	0	Q = 1
            // 1	1	Restricted combination
            // mofre info: http://en.wikipedia.org/wiki/Flip-flop_(electronics)

            var diagram = new DigitalLogicDiagram()
            {
                Id = Guid.NewGuid()
            };

            var input1 = new DigitalSignal()
            {
                Id   = Guid.NewGuid(),
                Name = "R",
                X    = 0,
                Y    = 90
            };

            var input2 = new DigitalSignal()
            {
                Id   = Guid.NewGuid(),
                Name = "S",
                X    = 0,
                Y    = 150
            };

            var output1 = new DigitalSignal()
            {
                Id   = Guid.NewGuid(),
                Name = "Q",
                X    = 270,
                Y    = 90
            };

            var output2 = new DigitalSignal() // TODO: Q' must be 'true' for the init value for the SR ("set-reset") latch
            {
                Id   = Guid.NewGuid(),
                Name = "Q'",
                X    = 270,
                Y    = 150
            };

            var norGate1 = new NorGate()
            {
                Id      = Guid.NewGuid(),
                Name    = "NorGate1",
                Inputs  = { input1, output2 },
                Outputs = { output1 }, // TODO: add Inputs before Outputs to properly init diagram
                X       = 180,
                Y       = 90
            };

            var norGate2 = new NorGate()
            {
                Id      = Guid.NewGuid(),
                Name    = "NorGate2",
                Inputs  = { input2, output1 },
                Outputs = { output2 }, // TODO: add Inputs before Outputs to properly init diagram
                X       = 180,
                Y       = 150
            };

            var wire1 = new DigitalWire()
            {
                Id       = Guid.NewGuid(),
                Name     = "wire1",
                Signal   = input1,
                StartPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "startPin",
                    X    = 120,
                    Y    = 105
                },
                EndPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "endPin",
                    X    = 180,
                    Y    = 105
                }
            };

            var wire2 = new DigitalWire()
            {
                Id       = Guid.NewGuid(),
                Name     = "wire2",
                Signal   = input2,
                StartPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "startPin",
                    X    = 120,
                    Y    = 165
                },
                EndPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "endPin",
                    X    = 180,
                    Y    = 165
                }
            };

            var wire3 = new DigitalWire()
            {
                Id       = Guid.NewGuid(),
                Name     = "wire3",
                Signal   = output1,
                StartPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "startPin",
                    X    = 218,
                    Y    = 105
                },
                EndPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "endPin",
                    X    = 270,
                    Y    = 105
                }
            };

            var wire4 = new DigitalWire()
            {
                Id       = Guid.NewGuid(),
                Name     = "wire4",
                Signal   = output2,
                StartPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "startPin",
                    X    = 218,
                    Y    = 165
                },
                EndPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "endPin",
                    X    = 270,
                    Y    = 165
                }
            };

            var wire5 = new DigitalWire()
            {
                Id       = Guid.NewGuid(),
                Name     = "wire5",
                Signal   = output1,
                StartPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "startPin",
                    X    = 240,
                    Y    = 105
                },
                EndPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "endPin",
                    X    = 195,
                    Y    = 150
                }
            };

            var wire6 = new DigitalWire()
            {
                Id       = Guid.NewGuid(),
                Name     = "wire6",
                Signal   = output2,
                StartPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "startPin",
                    X    = 240,
                    Y    = 165
                },
                EndPin = new DigitalPin()
                {
                    Id   = Guid.NewGuid(),
                    Name = "endPin",
                    X    = 195,
                    Y    = 120
                }
            };

            diagram.Elements.Add(wire1);
            diagram.Elements.Add(wire2);
            diagram.Elements.Add(wire3);
            diagram.Elements.Add(wire4);
            diagram.Elements.Add(wire5);
            diagram.Elements.Add(wire6);
            diagram.Elements.Add(norGate1);
            diagram.Elements.Add(norGate2);
            diagram.Elements.Add(input1);
            diagram.Elements.Add(input2);
            diagram.Elements.Add(output1);
            diagram.Elements.Add(output2);

            // initialize input/output vector
            output1.State = false; // Q
            output2.State = false; // Q'
            input2.State  = false; // S
            input1.State  = false; // R

            diagram.ObserveInputs(scheduler, diagram.Disposables);
            diagram.ObserveElements(scheduler, diagram.Disposables);

            return(diagram);
        }