Ejemplo n.º 1
0
        public void TestNor()
        {
            Source srctrue  = new Source(true);
            Source srcfalse = new Source(false);
            NOR    nor      = new NOR();

            nor.addInput(srcfalse);
            nor.addInput(srcfalse);
            NOR nor2 = new NOR();

            nor2.addInput(srcfalse);
            nor2.addInput(srctrue);
            NOR nor3 = new NOR();

            nor3.addInput(srctrue);
            nor3.addInput(srcfalse);
            NOR nor4 = new NOR();

            nor4.addInput(srctrue);
            nor4.addInput(srctrue);

            srctrue.Execute();
            srcfalse.Execute();

            Assert.AreEqual(nor.state, true);
            Assert.AreEqual(nor2.state, false);
            Assert.AreEqual(nor3.state, false);
            Assert.AreEqual(nor4.state, false);
        }
Ejemplo n.º 2
0
        public Object visit(NOR nor, string s)
        {
            Label label = getBaseLabel();

            label.Content = s + " - " + "NOR";
            return(label);
        }
Ejemplo n.º 3
0
        public void NOR_Events_GateOn()
        {
            // arrange
            var nor = new NOR("test");

            nor.V.V = VoltageSignal.HIGH;
            bool fired = false;

            nor.O.Changed += _ => fired = true;

            // act, assert
            nor.B.V = VoltageSignal.HIGH;
            Assert.IsTrue(fired, "Gate on -- A: L; B: ^; event");
            fired   = false;
            nor.B.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "Gate on -- A: L; B: -->H; no event");
            nor.B.V = VoltageSignal.LOW;
            Assert.IsTrue(fired, "Gate on -- A: L; B: v; event");
            fired   = false;
            nor.B.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "Gate on -- A: L; B: -->L; no event");
            nor.A.V = VoltageSignal.HIGH;
            Assert.IsTrue(fired, "Gate on -- B: L; A: ^; event");
            fired   = false;
            nor.A.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "Gate on -- B: L; A: -->H; no event");
            nor.A.V = VoltageSignal.LOW;
            Assert.IsTrue(fired, "Gate on -- B: L; A: v; event");
            fired   = false;
            nor.A.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "Gate on -- B: L; A: -->L; no event");

            // setup
            nor.A.V = VoltageSignal.HIGH;
            nor.B.V = VoltageSignal.LOW;
            fired   = false;
            // test
            nor.B.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "Gate on -- A: H; B: ^; no event");
            nor.B.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "Gate on -- A: H; B: -->H; no event");
            nor.B.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "Gate on -- A: H; B: v; no event");
            nor.B.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "Gate on -- A: H; B: -->L; no event");

            // setup
            nor.A.V = VoltageSignal.LOW;
            nor.B.V = VoltageSignal.HIGH;
            fired   = false;
            // test
            nor.A.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "Gate on -- B: H; A: ^; no event");
            nor.A.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "Gate on -- B: H; A: -->H; no event");
            nor.A.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "Gate on -- B: H; A: v; no event");
            nor.A.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "Gate on -- B: H; A: -->L; no event");
        }
Ejemplo n.º 4
0
 public L_Nor(int input, int id, NOR v_Nor) : base(input, 2, id)      //Output[0] = Normal [1] = Negiert
 {
     this.v_Nor = v_Nor;
     output[0]  = !output[1];                       //output[0] = Q output[1] = !Q
     for (int i = 0; i < input; i++)
     {
         this.input[i] = false;
     }
 }
Ejemplo n.º 5
0
        public void NOR_Event_GateOnOff()
        {
            // arrange
            var  nor   = new NOR("test");
            bool fired = false;

            nor.O.Changed += _ => fired = true;

            // act, assert
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsTrue(fired, "A: L; B: L; V: ^; event");
            fired   = false;
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "A: L; B: L; V: --->H; no event");
            nor.V.V = VoltageSignal.LOW;
            Assert.IsTrue(fired, "A: L; B: L; V: v; event");
            fired   = false;
            nor.V.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "A: L; B: L; V: --->L; no event");

            nor.A.V = VoltageSignal.HIGH;
            fired   = false;
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "A: H; B: L; V: ^; no event");
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "A: H; B: L; V: --->H; no event");
            nor.V.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "A: H; B: L; V: v; no event");
            nor.V.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "A: H; B: L; V: --->L; no event");

            nor.A.V = VoltageSignal.LOW;
            nor.B.V = VoltageSignal.HIGH;
            fired   = false;
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "A: L; B: H; V: ^; no event");
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "A: L; B: H; V: --->H; no event");
            nor.V.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "A: L; B: H; V: v; no event");
            nor.V.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "A: L; B: H; V: --->L; no event");

            nor.A.V = VoltageSignal.HIGH;
            fired   = false;
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "A: H; B: H; V: ^; no event");
            nor.V.V = VoltageSignal.HIGH;
            Assert.IsFalse(fired, "A: H; B: H; V: --->H; no event");
            nor.V.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "A: H; B: H; V: v; no event");
            nor.V.V = VoltageSignal.LOW;
            Assert.IsFalse(fired, "A: H; B: H; V: --->L; no event");
        }
Ejemplo n.º 6
0
        public void NOR_Constructor()
        {
            // arrange, act
            var nor = new NOR("test");

            // assert
            Assert.AreEqual(VoltageSignal.LOW, nor.V.V, "Constructor: Voltage");
            Assert.AreEqual(VoltageSignal.LOW, nor.A.V, "Constructor: A");
            Assert.AreEqual(VoltageSignal.LOW, nor.B.V, "Constructor: B");
            Assert.AreEqual(VoltageSignal.LOW, nor.O.V, "Constructor: O");
            Assert.AreEqual("LOW", nor.ToString(), "Constructor: ToString()");
        }
Ejemplo n.º 7
0
        public void NOR(VoltageSignal voltage, VoltageSignal a, VoltageSignal b, VoltageSignal expected)
        {
            // arrage
            var nor = new NOR("test");

            // act
            nor.V.V = voltage;
            nor.A.V = a;
            nor.B.V = b;

            // assert
            Assert.AreEqual(expected, nor.O.V, $"V:{nor.V}; A:{nor.A}; B:{nor.B}");
        }
Ejemplo n.º 8
0
        public void NOR_TwoNegative_PositiveOutput()
        {
            // Arrange
            var port = new NOR();

            port.Previous.Add(new Input {
                Value = Bit.LOW
            });
            port.Previous.Add(new Input {
                Value = Bit.LOW
            });

            // Act
            port.Calculate();

            // Assert
            Assert.AreEqual(Bit.HIGH, port.Value);
        }
Ejemplo n.º 9
0
        private void createGateDueToType(PaintEventArgs e)
        {
            //switch can be replaced by a one line of code using runtime Creation ((gotta GOOGLE it))
            Gate g;

            switch (gateType)
            {
            case "OR":
                g = new OR();
                break;

            case "NOT":
                g = new NOT();
                break;

            case "AND":
                g = new AND();
                break;

            case "NAND":
                g = new NAND();
                break;

            case "NOR":
                g = new NOR();
                break;

            case "XOR":
                g = new XOR();
                break;

            case "XNOR":
                g = new XNOR();
                break;

            default:
                g = null;
                break;
            }
            g.Draw(e);
        }
Ejemplo n.º 10
0
        public void NOR_InputChanged_OutputUpdatesCorrectly()
        {
            //When both inputs are off output should be on
            NOR norGate = new NOR();

            Assert.IsTrue(norGate.Output.value);

            //Any other option - output is off

            norGate.InputA.value = true;
            Assert.IsFalse(norGate.Output.value);

            norGate.InputB.value = true;
            Assert.IsFalse(norGate.Output.value);

            norGate.InputA.value = false;
            Assert.IsFalse(norGate.Output.value);

            //When both inputs are off again output should be on again
            norGate.InputB.value = false;
            Assert.IsTrue(norGate.Output.value);
        }
Ejemplo n.º 11
0
        public List <StandardComponent> parcourir_copier()
        {
            UIElement[] tableau            = new UIElement[1000];
            List <StandardComponent> liste = new List <StandardComponent>();
            int length = canvas.Children.Count;

            canvas.Children.CopyTo(tableau, 0);
            for (int i = 0; i < length; i++)
            {
                StandardComponent newChild = null;
                if (!(typeof(Line) == tableau[i].GetType()) && ((tableau[i] as StandardComponent).IsSelect))
                {
                    if (typeof(AND) == tableau[i].GetType())
                    {
                        newChild = new AND((tableau[i] as AND).nbrInputs());
                        for (int j = 0; j < (tableau[i] as AND).nbrInputs(); j++)
                        {
                            Terminal terminal_1 = (Terminal)((tableau[i] as AND).inputStack.Children[j]);
                            Terminal terminal_2 = (Terminal)((newChild as AND).inputStack.Children[j]);

                            if (terminal_1.IsInversed)
                            {
                                terminal_2.IsInversed = true;
                                terminal_2.input_inversed();
                            }
                        }
                    }
                    else if (typeof(OR) == tableau[i].GetType())
                    {
                        newChild = new OR((tableau[i] as OR).nbrInputs());
                        for (int j = 0; j < (tableau[i] as OR).nbrInputs(); j++)
                        {
                            Terminal terminal_1 = (Terminal)((tableau[i] as OR).inputStack.Children[j]);
                            Terminal terminal_2 = (Terminal)((newChild as OR).inputStack.Children[j]);

                            if (terminal_1.IsInversed)
                            {
                                terminal_2.IsInversed = true;
                                terminal_2.input_inversed();
                            }
                        }
                    }

                    else if (typeof(NAND) == tableau[i].GetType())
                    {
                        newChild = new NAND((tableau[i] as NAND).nbrInputs());
                        for (int j = 0; j < (tableau[i] as NAND).nbrInputs(); j++)
                        {
                            Terminal terminal_1 = (Terminal)((tableau[i] as NAND).inputStack.Children[j]);
                            Terminal terminal_2 = (Terminal)((newChild as NAND).inputStack.Children[j]);

                            if (terminal_1.IsInversed)
                            {
                                terminal_2.IsInversed = true;
                                terminal_2.input_inversed();
                            }
                        }
                    }
                    else if (typeof(NOR) == tableau[i].GetType())
                    {
                        newChild = new NOR((tableau[i] as NOR).nbrInputs());
                        for (int j = 0; j < (tableau[i] as NOR).nbrInputs(); j++)
                        {
                            Terminal terminal_1 = (Terminal)((tableau[i] as NOR).inputStack.Children[j]);
                            Terminal terminal_2 = (Terminal)((newChild as NOR).inputStack.Children[j]);

                            if (terminal_1.IsInversed)
                            {
                                terminal_2.IsInversed = true;
                                terminal_2.input_inversed();
                            }
                        }
                    }

                    else if (typeof(Not) == tableau[i].GetType())
                    {
                        newChild = new Not();

                        Terminal terminal_1 = (Terminal)((tableau[i] as Not).inputStack.Children[0]);
                        Terminal terminal_2 = (Terminal)((newChild as Not).inputStack.Children[0]);

                        if (terminal_1.IsInversed)
                        {
                            terminal_2.IsInversed = true;
                            terminal_2.input_inversed();
                        }
                    }

                    else if (typeof(Output) == tableau[i].GetType())
                    {
                        newChild = new Output();
                    }

                    else if (typeof(Input) == tableau[i].GetType())
                    {
                        newChild = new Input();
                        (newChild as Input).state = (tableau[i] as Input).state;
                    }

                    else if (typeof(XNOR) == tableau[i].GetType())
                    {
                        newChild = new XNOR((tableau[i] as XNOR).nbrInputs());
                        for (int j = 0; j < (tableau[i] as XNOR).nbrInputs(); j++)
                        {
                            Terminal terminal_1 = (Terminal)((tableau[i] as XNOR).inputStack.Children[j]);
                            Terminal terminal_2 = (Terminal)((newChild as XNOR).inputStack.Children[j]);

                            if (terminal_1.IsInversed)
                            {
                                terminal_2.IsInversed = true;
                                terminal_2.input_inversed();
                            }
                        }
                    }
                    else if (typeof(XOR) == tableau[i].GetType())
                    {
                        newChild = new XOR((tableau[i] as XOR).nbrInputs());
                        for (int j = 0; j < (tableau[i] as XOR).nbrInputs(); j++)
                        {
                            Terminal terminal_1 = (Terminal)((tableau[i] as XOR).inputStack.Children[j]);
                            Terminal terminal_2 = (Terminal)((newChild as XOR).inputStack.Children[j]);

                            if (terminal_1.IsInversed)
                            {
                                terminal_2.IsInversed = true;
                                terminal_2.input_inversed();
                            }
                        }
                    }

                    else if (typeof(Comparateur) == tableau[i].GetType())
                    {
                        newChild = new Comparateur((tableau[i] as Comparateur).nbrInputs(), (tableau[i] as Comparateur).nbrOutputs());
                    }

                    else if (typeof(Decodeur) == tableau[i].GetType())
                    {
                        newChild = new Decodeur((tableau[i] as Decodeur).nbrInputs(), (tableau[i] as Decodeur).nbrOutputs());
                    }

                    else if (typeof(Demultiplexer) == tableau[i].GetType())
                    {
                        newChild = new Demultiplexer((tableau[i] as Demultiplexer).nbrInputs(), (tableau[i] as Demultiplexer).nbrOutputs(), (tableau[i] as Demultiplexer).nbrSelections());
                    }

                    else if (typeof(Encodeur) == tableau[i].GetType())
                    {
                        newChild = new Encodeur((tableau[i] as Encodeur).nbrInputs(), (tableau[i] as Encodeur).nbrOutputs());
                    }

                    else if (typeof(FullAdder) == tableau[i].GetType())
                    {
                        newChild = new FullAdder((tableau[i] as FullAdder).nbrInputs(), (tableau[i] as FullAdder).nbrOutputs());
                    }

                    else if (typeof(FullSub) == tableau[i].GetType())
                    {
                        newChild = new FullSub((tableau[i] as FullSub).nbrInputs(), (tableau[i] as FullSub).nbrOutputs());
                    }

                    else if (typeof(HalfAdder) == tableau[i].GetType())
                    {
                        newChild = new HalfAdder((tableau[i] as HalfAdder).nbrInputs(), (tableau[i] as HalfAdder).nbrOutputs());
                    }

                    else if (typeof(HalfSub) == tableau[i].GetType())
                    {
                        newChild = new HalfSub((tableau[i] as HalfSub).nbrInputs(), (tableau[i] as HalfSub).nbrOutputs());
                    }

                    else if (typeof(Multiplexer) == tableau[i].GetType())
                    {
                        newChild = new Multiplexer((tableau[i] as Multiplexer).nbrInputs(), (tableau[i] as Multiplexer).nbrOutputs(), (tableau[i] as Multiplexer).nbrSelections());
                    }

                    else if (typeof(SequentialComponent.Clock) == tableau[i].GetType())
                    {
                        newChild = new SequentialComponent.Clock((tableau[i] as SequentialComponent.Clock).LowLevelms, (tableau[i] as SequentialComponent.Clock).HighLevelms, MainWindow.Delay);
                    }

                    liste.Add(newChild);
                    newChild.AllowDrop = true;
                    newChild.PreviewMouseLeftButtonDown += fenetre.MouseLeftButtonDown;
                    newChild.PreviewMouseMove           += fenetre.MouseMove;
                    newChild.PreviewMouseLeftButtonUp   += fenetre.PreviewMouseLeftButtonUp;
                    newChild.SetValue(Canvas.LeftProperty, tableau[i].GetValue(Canvas.LeftProperty));
                    newChild.SetValue(Canvas.TopProperty, tableau[i].GetValue(Canvas.TopProperty));
                    (newChild as StandardComponent).PosX = (tableau[i] as StandardComponent).PosX;
                    (newChild as StandardComponent).PosY = (tableau[i] as StandardComponent).PosY;

                    try
                    {
                        StandardComponent component = newChild as StandardComponent;
                        component.recalculer_pos();
                    }
                    catch { };
                }
            }
            return(liste);
        }