Beispiel #1
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
        }