Beispiel #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);
        }
Beispiel #2
0
        public void Counter()
        {
            #region Startup
            var  TestTable = new LadderDataTable();
            Node PowerRail = new Node();

            CTC ctc = new CTC();
            ctc.Name      = "1";
            ctc.Limit     = "Limit";
            ctc.LeftLide  = PowerRail;
            ctc.DataTable = TestTable;

            CTD ctd = new CTD();
            ctd.Name      = "1";
            ctd.Limit     = "Limit";
            ctd.LeftLide  = PowerRail;
            ctd.DataTable = TestTable;

            CTU ctu = new CTU();
            ctu.Name      = "1";
            ctu.Limit     = "Limit";
            ctu.LeftLide  = PowerRail;
            ctu.DataTable = TestTable;

            RES res = new RES();
            res.Name      = "1";
            res.LeftLide  = PowerRail;
            res.DataTable = TestTable;
            #endregion Startup

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

            Trace.WriteLine("StartUP", "CTC");
            Trace.Indent();
            PowerRail.LogicLevel = true;
            ctc.CurrentValue     = 1;
            ctc.LimitValue       = 2;
            res.Execute();
            Trace.Unindent();

            Trace.WriteLine("Input False", "CTC");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            ctc.Execute();
            ctc.Execute();
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState);
            Trace.Unindent();

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

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState, "Fail First Cycle");

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsTrue(ctc.InternalState, "Fail Second Cycle");

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState, "Fail Third Cycle");

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState, "Fail Fourth Cycle");

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

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

            Trace.WriteLine("StartUP", "CTD");
            Trace.Indent();
            PowerRail.LogicLevel = true;
            ctc.CurrentValue     = 3;
            ctc.LimitValue       = 1;
            Trace.Unindent();

            Trace.WriteLine("Input False", "CTD");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            ctd.Execute();
            ctd.Execute();
            ctd.Execute();
            Assert.IsFalse(ctc.InternalState);
            Trace.Unindent();

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

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsTrue(ctd.InternalState, "Fail First Cycle");

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsTrue(ctd.InternalState, "Fail Second Cycle");

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsFalse(ctd.InternalState, "Fail Third Cycle");

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsFalse(ctd.InternalState, "Fail Fourth Cycle");

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

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

            Trace.WriteLine("StartUP", "CTU");
            Trace.Indent();
            PowerRail.LogicLevel = true;
            ctu.CurrentValue     = 1;
            ctu.LimitValue       = 3;
            res.Execute();
            Trace.Unindent();

            Trace.WriteLine("Input False", "CTU");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            ctu.Execute();
            ctu.Execute();
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState);
            Trace.Unindent();

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

            PowerRail.LogicLevel = false;
            ctu.Execute();
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState, "Fail First Cycle");

            PowerRail.LogicLevel = false;
            ctu.Execute();
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState, "Fail Second Cycle");

            PowerRail.LogicLevel = false;
            ctu.Execute();
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsTrue(ctu.InternalState, "Fail Third Cycle");

            PowerRail.LogicLevel = false;
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState, "Fail Fourth Cycle");
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsTrue(ctu.InternalState, "Fail Fourth Cycle");

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