Exemplo n.º 1
0
        public void Constants()
        {
            var  TestTable = new LadderDataTable();
            Node PowerRail = new Node();

            PowerRail.LogicLevel = true;

            Trace.WriteLine("Math", "Unit Test");
            Trace.Indent();
            Trace.WriteLine("StartUP", "ADD");
            Trace.Indent();
            ADD add = new ADD();

            add.DataTable   = TestTable;
            add.LeftLide    = PowerRail;
            add.Destination = "Dest";
            add.VarA        = "1";
            add.ValueA      = 3;
            add.VarB        = "2";
            add.ValueB      = 1;
            add.Execute();
            Trace.Unindent();

            Trace.WriteLine("StartUP", "MOV");
            Trace.Indent();
            MOV mov = new MOV();

            mov.DataTable   = TestTable;
            mov.LeftLide    = PowerRail;
            mov.Destination = "Dest";
            mov.VarA        = "0";
            mov.ValueA      = 1;
            mov.Execute();
            Trace.Unindent();
            Trace.Unindent();

            Trace.WriteLine("Counter", "Unit Test");
            Trace.Indent();
            Trace.WriteLine("StartUP", "CTC");
            Trace.Indent();
            CTC ctc = new CTC();

            ctc.DataTable  = TestTable;
            ctc.Name       = "1";
            ctc.Limit      = "2";
            ctc.LimitValue = 3;
            ctc.LeftLide   = PowerRail;
            ctc.Execute();
            Trace.Unindent();

            Trace.WriteLine("StartUP", "CTU");
            Trace.Indent();
            CTU ctu = new CTU();

            ctu.DataTable  = TestTable;
            ctu.Name       = "1";
            ctu.Limit      = "3";
            ctu.LimitValue = 4;
            ctu.LeftLide   = PowerRail;
            ctu.Execute();
            Trace.Unindent();
            Trace.Unindent();

            Trace.WriteLine("Compare", "Unit Test");
            Trace.Indent();
            EQU equ = new EQU();

            equ.DataTable = TestTable;
            equ.LeftLide  = PowerRail;
            equ.VarA      = "3";
            equ.ValueA    = 4;
            equ.VarB      = "4";
            equ.ValueB    = 5;
            equ.Execute();
            Trace.Unindent();

            Assert.AreEqual(2, TestTable.Count);
        }
Exemplo n.º 2
0
        public void Math()
        {
            #region Startup
            var  TestTable = new LadderDataTable();
            Node PowerRail = new Node();

            ADD add = new ADD();
            add.LeftLide    = PowerRail;
            add.Destination = "Dest";
            add.VarA        = "VarA";
            add.VarB        = "VarB";
            add.DataTable   = TestTable;

            DIV div = new DIV();
            div.LeftLide    = PowerRail;
            div.Destination = "Dest";
            div.VarA        = "VarA";
            div.VarB        = "VarB";
            div.DataTable   = TestTable;

            MOV mov = new MOV();
            mov.LeftLide    = PowerRail;
            mov.Destination = "Dest";
            mov.VarA        = "VarA";
            mov.DataTable   = TestTable;

            MUL mul = new MUL();
            mul.LeftLide    = PowerRail;
            mul.Destination = "Dest";
            mul.VarA        = "VarA";
            mul.VarB        = "VarB";
            mul.DataTable   = TestTable;

            SUB sub = new SUB();
            sub.LeftLide    = PowerRail;
            sub.Destination = "Dest";
            sub.VarA        = "VarA";
            sub.VarB        = "VarB";
            sub.DataTable   = TestTable;
            #endregion Startup

            #region ADD
            Trace.WriteLine("ADD", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "ADD");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            add.ValueA = 1;
            add.ValueB = 2;
            Trace.Unindent();

            Trace.WriteLine("Input False", "ADD");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            add.Execute();
            Assert.IsFalse(add.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "ADD");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            add.Execute();
            Assert.IsTrue(add.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)3);

            Trace.Unindent();
            Trace.Unindent();
            #endregion ADD

            #region DIV
            Trace.WriteLine("DIV", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "DIV");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            div.ValueA = 10;
            div.ValueB = 2;
            Trace.Unindent();

            Trace.WriteLine("Input False", "DIV");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            div.Execute();
            Assert.IsFalse(div.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "DIV");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            div.Execute();
            Assert.IsTrue(div.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)5);

            Trace.Unindent();
            Trace.Unindent();
            #endregion DIV

            #region MOV
            Trace.WriteLine("MOV", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "MOV");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            mov.ValueA = 10;
            Trace.Unindent();

            Trace.WriteLine("Input False", "MOV");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            mov.Execute();
            Assert.IsFalse(mov.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "MOV");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            mov.Execute();
            Assert.IsTrue(mov.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)10);

            Trace.Unindent();
            Trace.Unindent();
            #endregion MOV

            #region MUL
            Trace.WriteLine("MUL", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "MUL");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            mul.ValueA = 3;
            mul.ValueB = 6;
            Trace.Unindent();

            Trace.WriteLine("Input False", "MUL");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            mul.Execute();
            Assert.IsFalse(mul.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "MUL");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            mul.Execute();
            Assert.IsTrue(mul.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)18);

            Trace.Unindent();
            Trace.Unindent();
            #endregion MUL

            #region SUB
            Trace.WriteLine("SUB", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "SUB");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            sub.ValueA = 4;
            sub.ValueB = 6;
            Trace.Unindent();

            Trace.WriteLine("Input False", "SUB");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            sub.Execute();
            Assert.IsFalse(sub.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "SUB");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            sub.Execute();
            Assert.IsTrue(sub.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)-2);

            Trace.Unindent();
            Trace.Unindent();
            #endregion SUB
        }