Esempio n. 1
0
        public void BasicTests()
        {
            LadderDataTable TestTable = new LadderDataTable();

            TestTable.Add("Var1", typeof(int));
            TestTable.Add("Var1", typeof(int), LDVarClass.Data, 10);
            TestTable.Add("Var2", typeof(bool));
            TestTable.Add("Var3", typeof(byte));
            TestTable.Add("Var4", typeof(short));
            TestTable.Add("Var5", typeof(int));

            Assert.AreEqual(5, TestTable.Count, "Stored Variable number incorrect");

            TestTable.Rename("Var1", "Var6");
            TestTable.Rename("Var6", "Var5");
            TestTable.Remove("Var1");

            TestTable.SetValue(0, true);
            TestTable.SetValue("Var3", (byte)255);
            TestTable.SetValue(TestTable.GetIndexOf("Var4"), (short)777);

            Assert.AreEqual(4, TestTable.Count, "Stored Variable number incorrect");
        }
Esempio n. 2
0
        public void TypeSafetyTests()
        {
            LadderDataTable TestTable = new LadderDataTable();

            TestTable.Add("Var1", typeof(int));
            TestTable.Add("Var2", typeof(bool));

            try
            {
                TestTable.Add("Var1", typeof(bool));
                throw new AssertFailedException("Exception expected");
            }
            catch (ArgumentException ex)
            {
                StringAssert.Equals(ex.ParamName, "name");
                Assert.IsInstanceOfType(ex.InnerException, typeof(FormatException));
            }

            try
            {
                TestTable.Add("Var1", typeof(bool), LDVarClass.Data, false);
                throw new AssertFailedException("Exception expected");
            }
            catch (ArgumentException ex)
            {
                StringAssert.Equals(ex.ParamName, "name");
                Assert.IsInstanceOfType(ex.InnerException, typeof(FormatException));
            }

            try
            {
                TestTable.Add("Var3", typeof(int), LDVarClass.Data, null);
                throw new AssertFailedException("Exception expected");
            }
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains(ex.Message, "non-nullable");
                StringAssert.Equals(ex.ParamName, "value");
            }

            try
            {
                TestTable.Rename("Var2", "Var1");
                throw new AssertFailedException("Exception expected");
            }
            catch (ArgumentException ex)
            {
                StringAssert.Equals(ex.ParamName, "newName");
                Assert.IsInstanceOfType(ex.InnerException, typeof(FormatException));
            }

            try
            {
                TestTable.SetValue("Var1", "Var1");
                throw new AssertFailedException("Exception expected");
            }
            catch (FormatException ex)
            {
                StringAssert.Equals(ex.Message, "Value Type Mismatch");
            }

            try
            {
                TestTable.SetValue(0, "Var1");
                throw new AssertFailedException("Exception expected");
            }
            catch (FormatException ex)
            {
                StringAssert.Equals(ex.Message, "Value Type Mismatch");
            }
        }
Esempio n. 3
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
        }
Esempio n. 4
0
        public void Compare()
        {
            #region Startup
            var  TestTable = new LadderDataTable();
            Node PowerRail = new Node();

            EQU equ = new EQU();
            equ.LeftLide  = PowerRail;
            equ.VarA      = "VarA";
            equ.VarB      = "VarB";
            equ.DataTable = TestTable;

            GEQ geq = new GEQ();
            geq.LeftLide  = PowerRail;
            geq.VarA      = "VarA";
            geq.VarB      = "VarB";
            geq.DataTable = TestTable;

            GRT grt = new GRT();
            grt.LeftLide  = PowerRail;
            grt.VarA      = "VarA";
            grt.VarB      = "VarB";
            grt.DataTable = TestTable;

            LEG leg = new LEG();
            leg.LeftLide  = PowerRail;
            leg.VarA      = "VarA";
            leg.VarB      = "VarB";
            leg.DataTable = TestTable;

            LES les = new LES();
            les.LeftLide  = PowerRail;
            les.VarA      = "VarA";
            les.VarB      = "VarB";
            les.DataTable = TestTable;

            NEQ neq = new NEQ();
            neq.LeftLide  = PowerRail;
            neq.VarA      = "VarA";
            neq.VarB      = "VarB";
            neq.DataTable = TestTable;
            #endregion Startup

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

            Trace.WriteLine("Input False", "EQU");
            Trace.Indent();
            PowerRail.LogicLevel = false;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(equ.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(equ.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsFalse(equ.Execute());
            Trace.Unindent();

            Trace.WriteLine("Input True", "EQU");
            Trace.Indent();
            PowerRail.LogicLevel = true;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsTrue(equ.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(equ.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsFalse(equ.Execute());
            Trace.Unindent();
            Trace.Unindent();
            #endregion EQU

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

            Trace.WriteLine("Input False", "GEQ");
            Trace.Indent();
            PowerRail.LogicLevel = false;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(geq.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(geq.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsFalse(geq.Execute());
            Trace.Unindent();

            Trace.WriteLine("Input True", "GEQ");
            Trace.Indent();
            PowerRail.LogicLevel = true;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsTrue(geq.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(geq.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsTrue(geq.Execute());
            Trace.Unindent();
            Trace.Unindent();
            #endregion GEQ

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

            Trace.WriteLine("Input False", "GRT");
            Trace.Indent();
            PowerRail.LogicLevel = false;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            grt.Execute();
            Assert.IsFalse(grt.InternalState);

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            grt.Execute();
            Assert.IsFalse(grt.InternalState);

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            grt.Execute();
            Assert.IsFalse(grt.InternalState);
            Trace.Unindent();

            Trace.WriteLine("Input True", "GRT");
            Trace.Indent();
            PowerRail.LogicLevel = true;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            grt.Execute();
            Assert.IsFalse(grt.InternalState);

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            grt.Execute();
            Assert.IsFalse(grt.InternalState);

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            grt.Execute();
            Assert.IsTrue(grt.InternalState);
            Trace.Unindent();
            Trace.Unindent();
            #endregion GRT

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

            Trace.WriteLine("Input False", "LEG");
            Trace.Indent();
            PowerRail.LogicLevel = false;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            leg.Execute();
            Assert.IsFalse(leg.InternalState);

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            leg.Execute();
            Assert.IsFalse(leg.InternalState);

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            leg.Execute();
            Assert.IsFalse(leg.InternalState);
            Trace.Unindent();

            Trace.WriteLine("Input True", "LEG");
            Trace.Indent();
            PowerRail.LogicLevel = true;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            leg.Execute();
            Assert.IsTrue(leg.InternalState);

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            leg.Execute();
            Assert.IsTrue(leg.InternalState);

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            leg.Execute();
            Assert.IsFalse(leg.InternalState);
            Trace.Unindent();
            Trace.Unindent();
            #endregion LEG

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

            Trace.WriteLine("Input False", "LES");
            Trace.Indent();
            PowerRail.LogicLevel = false;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(les.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(les.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsFalse(les.Execute());
            Trace.Unindent();

            Trace.WriteLine("Input True", "LES");
            Trace.Indent();
            PowerRail.LogicLevel = true;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(les.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsTrue(les.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsFalse(les.Execute());
            Trace.Unindent();
            Trace.Unindent();
            #endregion LES

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

            Trace.WriteLine("Input False", "NEQ");
            Trace.Indent();
            PowerRail.LogicLevel = false;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(neq.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(neq.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsFalse(neq.Execute());
            Trace.Unindent();

            Trace.WriteLine("Input True", "NEQ");
            Trace.Indent();
            PowerRail.LogicLevel = true;

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)1);
            Assert.IsFalse(neq.Execute());

            TestTable.SetValue(0, (short)0);
            TestTable.SetValue(1, (short)1);
            Assert.IsTrue(neq.Execute());

            TestTable.SetValue(0, (short)1);
            TestTable.SetValue(1, (short)0);
            Assert.IsTrue(neq.Execute());
            Trace.Unindent();
            Trace.Unindent();
            #endregion NEQ
        }