public void inverterTest()
        {
            ElementsFactory factory = ElementsFactory.getInstance();

            PortElement a = factory.createPortElement(PortDirection.Input, "a");
            PortElement b = factory.createPortElement(PortDirection.Output, "b");

            ILogicalElement inverter = factory.createLogicalElement(LibraryElementKind.Enum.Inverter, 1);

            Utils.Evaluator evaluator = new Utils.Evaluator(inverter, new PortList {
                b
            });

            inverter.makeConnection(a, 0, 0);

            b.makeConnection(inverter, 0, 0);

            a.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b.Value, LogicValue.Enum.Low);

            a.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b.Value, LogicValue.Enum.High);

            a.Value = LogicValue.Enum.Unknown;
            evaluator.evaluate();
            Assert.AreEqual(b.Value, LogicValue.Enum.Unknown);

            a.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b.Value, LogicValue.Enum.DontCare);
        }
Exemple #2
0
        public void simple_2_1_Mux()
        {
            ElementsFactory factory = ElementsFactory.getInstance();

            factory.reset();

            ILogicalElement mux = factory.createLogicalElement(LibraryElementKind.Enum.MUX, 1);

            PortElement a_port  = factory.createPortElement(PortDirection.Input, "a");
            PortElement b_port  = factory.createPortElement(PortDirection.Input, "b");
            PortElement address = factory.createPortElement(PortDirection.Input, "adr");

            PortElement c_port = factory.createPortElement(PortDirection.Output, "c");

            Utils.Evaluator evaluator = new Utils.Evaluator(mux, new PortList {
                c_port
            });

            mux.makeConnection(a_port, 0, 0);
            mux.makeConnection(b_port, 1, 0);
            mux.makeConnection(address, 2, 0);

            c_port.makeConnection(mux, 1, 0);

            address.Value = LogicValue.Enum.Low;
            a_port.Value  = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Unknown);

            a_port.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Unknown);

            address.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Unknown);

            b_port.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);

            b_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(c_port.Value, LogicValue.Enum.High);
        }
        public void simple2AND()
        {
            ElementsFactory factory = ElementsFactory.getInstance();

            factory.reset();

            PortElement a = factory.createPortElement(PortDirection.Input, "a");
            PortElement b = factory.createPortElement(PortDirection.Input, "b");

            PortElement c = factory.createPortElement(PortDirection.Output, "c");

            ILogicalElement and2 = factory.createLogicalElement(LibraryElementKind.Enum.AND, 2);

            Utils.Evaluator evaluator = new Utils.Evaluator(and2, new PortList {
                c
            });

            and2.makeConnection(a, 0, 0);
            and2.makeConnection(b, 1, 0);

            c.makeConnection(and2, 0, 0);

            a.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(c.Value, LogicValue.Enum.Unknown);

            b.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(c.Value, LogicValue.Enum.Low);

            a.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(c.Value, LogicValue.Enum.High);

            a.Value = LogicValue.Enum.Unknown;
            evaluator.evaluate();
            Assert.AreEqual(c.Value, LogicValue.Enum.Unknown);
        }
Exemple #4
0
        public void simple_1_4_DMX()
        {
            ElementsFactory factory = ElementsFactory.getInstance();

            factory.reset();

            ILogicalElement dmx = factory.createLogicalElement(LibraryElementKind.Enum.DMX, 2);

            PortElement addressLow  = factory.createPortElement(PortDirection.Input, "a0");
            PortElement addressHigh = factory.createPortElement(PortDirection.Input, "a1");

            PortElement data = factory.createPortElement(PortDirection.Input, "data");

            PortElement enable = factory.createPortElement(PortDirection.Input, "en");

            PortElement b_port = factory.createPortElement(PortDirection.Output, "b");
            PortElement c_port = factory.createPortElement(PortDirection.Output, "c");
            PortElement d_port = factory.createPortElement(PortDirection.Output, "d");
            PortElement e_port = factory.createPortElement(PortDirection.Output, "e");

            Utils.Evaluator evaluator = new Utils.Evaluator(dmx, new PortList {
                b_port, c_port, d_port, e_port
            });

            dmx.makeConnection(addressLow, 0, 0);
            dmx.makeConnection(addressHigh, 1, 0);

            dmx.makeConnection(data, 2, 0);

            dmx.makeConnection(enable, 3, 0);

            b_port.makeConnection(dmx, 0, 0);
            c_port.makeConnection(dmx, 0, 1);
            d_port.makeConnection(dmx, 0, 2);
            e_port.makeConnection(dmx, 0, 3);

            Assert.AreEqual(b_port.Value, LogicValue.Enum.Unknown);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Unknown);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Unknown);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Unknown);

            // enable = X

            enable.Value      = LogicValue.Enum.DontCare;
            addressHigh.Value = LogicValue.Enum.Low;
            addressLow.Value  = LogicValue.Enum.Low;
            data.Value        = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            addressHigh.Value = LogicValue.Enum.High;
            addressLow.Value  = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            // enable low

            enable.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            addressHigh.Value = LogicValue.Enum.DontCare;
            addressLow.Value  = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            //enable high
            // 00

            enable.Value = LogicValue.Enum.High;

            addressHigh.Value = LogicValue.Enum.Low;
            addressLow.Value  = LogicValue.Enum.Low;

            data.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);


            data.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.High);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            // 01

            addressHigh.Value = LogicValue.Enum.Low;
            addressLow.Value  = LogicValue.Enum.High;

            data.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.High);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            // 10

            addressHigh.Value = LogicValue.Enum.High;
            addressLow.Value  = LogicValue.Enum.Low;

            data.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.High);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            // 11

            addressHigh.Value = LogicValue.Enum.High;
            addressLow.Value  = LogicValue.Enum.High;

            data.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            data.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            // X1

            addressHigh.Value = LogicValue.Enum.DontCare;
            addressLow.Value  = LogicValue.Enum.High;

            data.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            data.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            // XX

            addressHigh.Value = LogicValue.Enum.DontCare;
            addressLow.Value  = LogicValue.Enum.DontCare;

            data.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            data.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            data.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(b_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(c_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(d_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            /***************************************************************************/
        }
        public void simple3AND()
        {
            ElementsFactory factory = ElementsFactory.getInstance();

            PortElement a = factory.createPortElement(PortDirection.Input, "a");
            PortElement b = factory.createPortElement(PortDirection.Input, "b");
            PortElement c = factory.createPortElement(PortDirection.Input, "c");

            PortElement d = factory.createPortElement(PortDirection.Output, "d");

            ILogicalElement and3 = factory.createLogicalElement(LibraryElementKind.Enum.AND, 3);

            Utils.Evaluator evaluator = new Utils.Evaluator(and3, new PortList {
                d
            });

            and3.makeConnection(a, 0, 0);
            and3.makeConnection(b, 1, 0);
            and3.makeConnection(c, 2, 0);

            d.makeConnection(and3, 0, 0);

            a.Value = LogicValue.Enum.Unknown;
            b.Value = LogicValue.Enum.Low;
            c.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            // U00
            Assert.AreEqual(d.Value, LogicValue.Enum.Unknown);

            a.Value = LogicValue.Enum.Low;
            b.Value = LogicValue.Enum.Unknown;
            c.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            // 0U1
            Assert.AreEqual(d.Value, LogicValue.Enum.Unknown);

            a.Value = LogicValue.Enum.DontCare;
            b.Value = LogicValue.Enum.High;
            c.Value = LogicValue.Enum.Unknown;
            evaluator.evaluate();
            // X1U
            Assert.AreEqual(d.Value, LogicValue.Enum.Unknown);

            a.Value = LogicValue.Enum.DontCare;
            b.Value = LogicValue.Enum.High;
            c.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            // X00
            Assert.AreEqual(d.Value, LogicValue.Enum.DontCare);

            a.Value = LogicValue.Enum.DontCare;
            b.Value = LogicValue.Enum.High;
            c.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            // X0X
            Assert.AreEqual(d.Value, LogicValue.Enum.DontCare);

            a.Value = LogicValue.Enum.Low;
            b.Value = LogicValue.Enum.DontCare;
            c.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            // 0XX
            Assert.AreEqual(d.Value, LogicValue.Enum.Low);

            a.Value = LogicValue.Enum.DontCare;
            b.Value = LogicValue.Enum.Low;
            c.Value = LogicValue.Enum.DontCare;
            // X0X
            Assert.AreEqual(d.Value, LogicValue.Enum.Low);

            a.Value = LogicValue.Enum.DontCare;
            b.Value = LogicValue.Enum.DontCare;
            c.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            // XX0
            Assert.AreEqual(d.Value, LogicValue.Enum.Low);

            a.Value = LogicValue.Enum.High;
            b.Value = LogicValue.Enum.High;
            c.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            // 111
            Assert.AreEqual(d.Value, LogicValue.Enum.High);

            a.Value = LogicValue.Enum.Low;
            b.Value = LogicValue.Enum.Low;
            c.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            // 001
            Assert.AreEqual(d.Value, LogicValue.Enum.Low);

            a.Value = LogicValue.Enum.High;
            b.Value = LogicValue.Enum.High;
            c.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            // 110
            Assert.AreEqual(d.Value, LogicValue.Enum.Low);

            a.Value = LogicValue.Enum.High;
            b.Value = LogicValue.Enum.Low;
            c.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            // 101
            Assert.AreEqual(d.Value, LogicValue.Enum.Low);
        }
Exemple #6
0
        public void simple_4_2_CD()
        {
            ElementsFactory factory = ElementsFactory.getInstance();

            factory.reset();

            ILogicalElement cd = factory.createLogicalElement(LibraryElementKind.Enum.ENC, 2);

            PortElement a_port = factory.createPortElement(PortDirection.Input, "a");
            PortElement b_port = factory.createPortElement(PortDirection.Input, "b");
            PortElement c_port = factory.createPortElement(PortDirection.Input, "c");
            PortElement d_port = factory.createPortElement(PortDirection.Input, "d");

            PortElement enable = factory.createPortElement(PortDirection.Input, "en");

            PortElement e_port = factory.createPortElement(PortDirection.Output, "e");
            PortElement f_port = factory.createPortElement(PortDirection.Output, "f");

            Utils.Evaluator evaluator = new Utils.Evaluator(cd, new PortList {
                e_port, f_port
            });

            cd.makeConnection(a_port, 0, 0);
            cd.makeConnection(b_port, 1, 0);
            cd.makeConnection(c_port, 2, 0);
            cd.makeConnection(d_port, 3, 0);

            cd.makeConnection(enable, 4, 0);

            e_port.makeConnection(cd, 0, 0);
            f_port.makeConnection(cd, 0, 1);

            Assert.AreEqual(e_port.Value, LogicValue.Enum.Unknown);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.Unknown);

            // enable = X

            enable.Value = LogicValue.Enum.DontCare;
            a_port.Value = LogicValue.Enum.Low;
            b_port.Value = LogicValue.Enum.Low;
            c_port.Value = LogicValue.Enum.Low;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.DontCare);

            a_port.Value = LogicValue.Enum.High;
            b_port.Value = LogicValue.Enum.High;
            c_port.Value = LogicValue.Enum.High;
            d_port.Value = LogicValue.Enum.High;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.DontCare);

            // enable low

            enable.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.Low);

            a_port.Value = LogicValue.Enum.High;
            b_port.Value = LogicValue.Enum.High;
            c_port.Value = LogicValue.Enum.High;
            d_port.Value = LogicValue.Enum.High;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.Low);

            //enable high
            // 1XXX

            enable.Value = LogicValue.Enum.High;

            a_port.Value = LogicValue.Enum.DontCare;
            b_port.Value = LogicValue.Enum.DontCare;
            c_port.Value = LogicValue.Enum.DontCare;
            d_port.Value = LogicValue.Enum.High;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.High);

            // 1010

            a_port.Value = LogicValue.Enum.Low;
            b_port.Value = LogicValue.Enum.High;
            c_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.High);

            // 01XX

            a_port.Value = LogicValue.Enum.DontCare;
            b_port.Value = LogicValue.Enum.DontCare;
            c_port.Value = LogicValue.Enum.High;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.High);

            // 0111

            a_port.Value = LogicValue.Enum.High;
            b_port.Value = LogicValue.Enum.High;
            c_port.Value = LogicValue.Enum.High;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.High);

            // 001X

            a_port.Value = LogicValue.Enum.DontCare;
            b_port.Value = LogicValue.Enum.High;
            c_port.Value = LogicValue.Enum.Low;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.Low);

            // 0011

            a_port.Value = LogicValue.Enum.High;
            b_port.Value = LogicValue.Enum.High;
            c_port.Value = LogicValue.Enum.Low;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.Low);

            // 0001

            a_port.Value = LogicValue.Enum.High;
            b_port.Value = LogicValue.Enum.Low;
            c_port.Value = LogicValue.Enum.Low;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.Low);

            // 0X01

            a_port.Value = LogicValue.Enum.High;
            b_port.Value = LogicValue.Enum.Low;
            c_port.Value = LogicValue.Enum.DontCare;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.DontCare);

            // 0000

            a_port.Value = LogicValue.Enum.Low;
            b_port.Value = LogicValue.Enum.Low;
            c_port.Value = LogicValue.Enum.Low;
            d_port.Value = LogicValue.Enum.Low;

            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);
            Assert.AreEqual(f_port.Value, LogicValue.Enum.DontCare);

            /***************************************************************************/
        }
Exemple #7
0
        public void simple_4_1_Mux()
        {
            ElementsFactory factory = ElementsFactory.getInstance();

            factory.reset();

            ILogicalElement mux = factory.createLogicalElement(LibraryElementKind.Enum.MUX, 2);

            PortElement a_port = factory.createPortElement(PortDirection.Input, "a");
            PortElement b_port = factory.createPortElement(PortDirection.Input, "b");
            PortElement c_port = factory.createPortElement(PortDirection.Input, "c");
            PortElement d_port = factory.createPortElement(PortDirection.Input, "d");

            PortElement addressLow  = factory.createPortElement(PortDirection.Input, "adr_l");
            PortElement addressHigh = factory.createPortElement(PortDirection.Input, "adr_h");

            PortElement e_port = factory.createPortElement(PortDirection.Output, "e");

            Utils.Evaluator evaluator = new Utils.Evaluator(mux, new PortList {
                e_port
            });

            mux.makeConnection(a_port, 0, 0);
            mux.makeConnection(b_port, 1, 0);
            mux.makeConnection(c_port, 2, 0);
            mux.makeConnection(d_port, 3, 0);

            mux.makeConnection(addressLow, 4, 0);
            mux.makeConnection(addressHigh, 5, 0);

            e_port.makeConnection(mux, 1, 0);

            Assert.AreEqual(e_port.Value, LogicValue.Enum.Unknown);

            // 000U
            // 00
            addressHigh.Value = LogicValue.Enum.Low;
            addressLow.Value  = LogicValue.Enum.Low;
            a_port.Value      = LogicValue.Enum.Unknown;
            b_port.Value      = LogicValue.Enum.Low;
            c_port.Value      = LogicValue.Enum.Low;
            d_port.Value      = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Unknown);

            //dcba
            //0000
            //1X

            addressHigh.Value = LogicValue.Enum.High;
            addressLow.Value  = LogicValue.Enum.DontCare;
            a_port.Value      = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            // 01
            addressHigh.Value = LogicValue.Enum.Low;
            addressLow.Value  = LogicValue.Enum.High;
            b_port.Value      = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            //1000
            //1X

            addressHigh.Value = LogicValue.Enum.High;
            addressLow.Value  = LogicValue.Enum.DontCare;
            d_port.Value      = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            //1100
            // 1X
            c_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            //11X0
            // 1X

            b_port.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            //11XX
            // 1X

            a_port.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            //11XX
            //X0

            addressHigh.Value = LogicValue.Enum.DontCare;
            addressLow.Value  = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            //11X0
            //X0

            a_port.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            // 11X1
            // X0

            a_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            // 11X1
            // XX

            addressLow.Value = LogicValue.Enum.DontCare;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            // 1101
            // XX

            b_port.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.DontCare);

            // 1111
            // XX

            b_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            // 0000
            // XX

            a_port.Value = LogicValue.Enum.Low;
            b_port.Value = LogicValue.Enum.Low;
            c_port.Value = LogicValue.Enum.Low;
            d_port.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            // 0000
            // 00

            addressLow.Value  = LogicValue.Enum.Low;
            addressHigh.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            //0001
            //00

            a_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            //0001
            //01

            addressLow.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            //0011
            //01

            b_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            //0011
            //11

            addressHigh.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            //1011
            //11

            d_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);

            //1011
            //10

            addressLow.Value = LogicValue.Enum.Low;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.Low);

            //1111
            //10

            c_port.Value = LogicValue.Enum.High;
            evaluator.evaluate();
            Assert.AreEqual(e_port.Value, LogicValue.Enum.High);
        }