Пример #1
0
        protected override void Run(string[] args)
        {
            AutoResetEvent waiter = new AutoResetEvent(false);
            int            data   = 0;
            var            clay1  = new Sender();

            var clay2 = new RClay(new RAgreement
            {
                SensorPoints = new List <object> {
                    "IN"
                },
                Response = (center, clay, cp) => {
                    data = center.GetSignal <int>("IN");
                    waiter.Set();
                }
            });

            Conduit.CreateLink(new LinkDef[] {
                new LinkDef(clay1, "OUT"),
                new LinkDef(clay2, "IN")
            });

            clay1.Test();

            waiter.WaitOne();
            Assert(data == 1, "Supposed to be 1");
        }
Пример #2
0
        protected override void Run(string[] args)
        {
            AutoResetEvent waiter = new AutoResetEvent(false);
            int            data   = 0;
            var            clay1  = new RClay(new RAgreement
            {
                SensorPoints = new List <object> {
                    "IN"
                },
                Response = (center, clay, cp) =>
                {
                    center["OUT"] = (center.GetSignal <int>("IN") + 1);
                }
            });

            var clay2 = new RClay(new RAgreement
            {
                SensorPoints = new List <object> {
                    "IN"
                },
                Response = (center, clay, cp) =>
                {
                    center["OUT"] = (center.GetSignal <int>("IN") * 2);
                }
            });


            var clay3 = new RClay(new RAgreement
            {
                SensorPoints = new List <object> {
                    "A", "B"
                },
                Response = (center, clay, cp) =>
                {
                    data = center.GetSignal <int>("A") + center.GetSignal <int>("B");
                    waiter.Set();
                }
            });

            var start = new Starter();

            var con1 = Conduit.CreateLink(new LinkDef(clay1, "IN"), new LinkDef(clay2, "IN"));
            var con2 = new Conduit();

            con2.Link(new LinkDef(start, "OUT"));

            con1.Link(new LinkDef(con2, "X"));

            Conduit.CreateLink(new LinkDef(clay1, "OUT"), new LinkDef(clay3, "A"));
            Conduit.CreateLink(new LinkDef(clay2, "OUT"), new LinkDef(clay3, "B"));

            start.Test(3);

            waiter.WaitOne();
            Assert(data == 10, "Data supposed to be");
        }
Пример #3
0
        protected override void Run(string[] args)
        {
            var clay1 = new RClay();
            var agr   = clay1.Agreement as RAgreement;

            Assert(agr.IsStaged == true, "IsStage is not true");

            var clay2 = new RClay();

            clay1.Connect(clay2, "P1");

            Assert(clay1._contacts["P1"] == clay2, "Did not make connection with clay2");

            clay1.Connect(clay2, "P2");

            Assert(clay1._contacts["P2"] == clay2, "Did not make connection with clay2");

            clay1.Connect(clay2, "P3");

            Assert(clay1._contacts.Count == 3, "Making connection with clays");

            var clay3 = new RClay();

            clay1.Connect(clay3, "P1");

            Assert(clay1._contacts["P1"] == clay3, "Did not make connection with clay3");

            Assert(clay1._contacts.Count == 3, "Missing connections, supposed to have 3 connections");

            clay1.Disconnect(clay1, "P1");

            Assert(clay1._contacts["P1"] == clay3, "clay3 should not be disconnected");
            Assert(clay1._contacts["P1"] == clay3, "clay3 should not be disconnected");
            Assert(clay1._contacts["P3"] == clay2, "clay2 should not be disconnected");

            clay1.Disconnect(clay2, "P3");
            Assert(clay1._contacts["P1"] == clay3, "clay3 should not be disconnected");
            Assert(clay1._contacts["P1"] == clay3, "clay3 should not be disconnected");

            Assert(!clay1._contacts.ContainsKey("P3"), "clay2 at P3 should be diconnected");

            Assert(clay1._contacts.Count == 2, "Should have only 2 connections left");


            clay1.Remember("As Manh", "This");
            clay1.Remember(1, "That");

            Assert(clay1.Recall("This") == (object)"As Manh", "Should have value of 'As Manh'");
            Assert((int)clay1.Recall("That") == 1, "Should remember value of 1");

            clay1.Forget("this");
            Assert(clay1.Recall("This") == (object)"As Manh", "Should not forget 'As Manh'");
            clay1.Forget("That");
            Assert(clay1.Recall("That") == null, "Should forget 1");
        }
Пример #4
0
        protected override void Run(string[] args)
        {
            var c     = new Conduit();
            var clay1 = new RClay();
            var clay2 = new RClay();
            var clay3 = new RClay();

            c.Link(new LinkDef[] {
                new LinkDef(clay1, "A"),
                new LinkDef(clay2, "B"),
                new LinkDef(clay3, "C")
            });

            c.Link(new LinkDef[] {
                new LinkDef(clay1, "A")
            });

            Assert(c._contacts.Count == 3, "Should have 3 connections");

            Assert(clay1._contacts["A"] == c, "Clay1 should have 1 connection with c");

            Assert(clay2._contacts["B"] == c, "Clay2 should have 1 connection with c");

            var test1 = c._contacts.FirstOrDefault(x => x.Clay == clay1 && x.ConnectPoint.Equals("A"));

            Assert(test1 != null, "Conduit supposed to have clay1 at point A");

            var test2 = c._contacts.FirstOrDefault(x => x.Clay == clay2 && x.ConnectPoint.Equals("B"));

            Assert(test2 != null, "Conduit supposed to have clay1 at point B");

            var test3 = c._contacts.FirstOrDefault(x => x.Clay == clay3 && x.ConnectPoint.Equals("C"));

            Assert(test3 != null, "Conduit supposed to have clay1 at point C");

            var testx = c._contacts.FirstOrDefault(x => x.Clay == clay2 && x.ConnectPoint.Equals("A"));

            Assert(testx == null, "Clay2 should not have point A in Conduit");


            c.Disconnect(clay2, "C");
            testx = c._contacts.FirstOrDefault(x => x.Clay == clay2 && x.ConnectPoint.Equals("B"));
            Assert(testx != null, "Clay2 should not be disconnected");

            c.Disconnect(clay2, "B");
            testx = c._contacts.FirstOrDefault(x => x.Clay == clay2 && x.ConnectPoint.Equals("B"));
            Assert(testx == null, "Clay2 should be disconnected");
        }
Пример #5
0
        protected override void Run(string[] args)
        {
            var waiter = new AutoResetEvent(false);
            var a1     = new Add2Number();
            var t1     = new Times2Number();
            var t2     = new Times2Number();

            var s1 = new Starter();
            var s2 = new Starter();

            Conduit.CreateLink(t1, "O", a1, "A");
            Conduit.CreateLink(t2, "O", a1, "B");

            float data = 0;

            SClay sclay = new SClay(new SAgreement
            {
                LayoutMap = new Dictionary <object, object[]> {
                    { "X", new object[] { t1, "A" } },
                    { "Y", new object[] { t2, "A" } },
                    { "O", new object[] { a1, "O" } }
                }
            });

            var vclay = new RClay(new RAgreement
            {
                SensorPoints = new List <object> {
                    "IN"
                },

                Response = (center, clay, sp) =>
                {
                    data = center.GetSignal <float>("IN");
                    waiter.Set();
                }
            });

            Conduit.CreateLink(sclay, "X", s1, "OUT");
            Conduit.CreateLink(sclay, "Y", s2, "OUT");
            Conduit.CreateLink(sclay, "O", vclay, "IN");

            s1.Test(.4f);
            s2.Test(.5f);
            waiter.WaitOne();
            Assert(data == 1.8f, "Supposed to be 1.8");
        }
Пример #6
0
        protected override void Run(string[] args)
        {
            var waiter = new AutoResetEvent(false);


            int data  = 0;
            var clay1 = new Starter();
            var clay2 = new Starter();
            var clay3 = new Starter();

            var clayx = new RClay(new RAgreement
            {
                SensorPoints = new List <object> {
                    "A", "B", "C"
                },
                Response = (center, clay, cp) => {
                    var A = center.GetSignal <int>("A");
                    var B = center.GetSignal <int>("B");
                    var C = center.GetSignal <int>("C");
                    data  = A + B + C;
                    waiter.Set();
                }
            });

            Conduit.CreateLink(new LinkDef[] {
                new LinkDef(clay1, "OUT"),
                new LinkDef(clayx, "A")
            });
            Conduit.CreateLink(new LinkDef[] {
                new LinkDef(clay2, "OUT"),
                new LinkDef(clayx, "B")
            });
            Conduit.CreateLink(new LinkDef[] {
                new LinkDef(clay3, "OUT"),
                new LinkDef(clayx, "C")
            });



            clay1.Test(1);
            clay2.Test(2);
            clay3.Test(3);

            waiter.WaitOne();
            Assert(data == 6, "Supposed to be 6");
        }
Пример #7
0
        public override void Test()
        {
            int          SumR = 0;
            int          MulR = 0;
            ResponseFunc f    = (RClay rc, object cp) => {
                int A = rc.GetSignals <int>("X");
                int B = rc.GetSignals <int>("Y");
                rc["Z"] = SumR = A + B;
            };

            ResponseFunc f2 = (RClay rc, object cp) => {
                int A = rc.GetSignals <int>("X");
                int B = rc.GetSignals <int>("Y");
                rc["Z"] = MulR = A * B;
            };

            RClay Add = new RClay(new Dictionary <string, object>()
            {
                { "Response", f },
                { "ConnectPoints", new List <Object> {
                      "X", "Y"
                  } }
            });

            RClay Mul = new RClay(new Dictionary <string, object>()
            {
                { "Response", f2 },
                { "ConnectPoints", new List <Object> {
                      "X", "Y"
                  } }
            });

            ///Conduit.CreateLink(Add, "Z", Mul, "X");

            SClay s = new SClay(new Dictionary <string, object>
            {
                {
                    "layoutMap", new List <SClayLayout> {
                        new SClayLayout {
                            HostConnectPoint  = "A",
                            AtConnectionPoint = "X",
                            WithClay          = Add
                        },
                        new SClayLayout {
                            HostConnectPoint  = "B",
                            AtConnectionPoint = "Y",
                            WithClay          = Add
                        },
                        new SClayLayout {
                            HostConnectPoint  = "SUM",
                            AtConnectionPoint = "Z",
                            WithClay          = Add
                        },
                        new SClayLayout {
                            HostConnectPoint  = "SUM",
                            AtConnectionPoint = "X",
                            WithClay          = Mul
                        },
                        new SClayLayout {
                            HostConnectPoint  = "C",
                            AtConnectionPoint = "Y",
                            WithClay          = Mul
                        }
                    }
                }
            });

            Clay.MakeConnection(s, this, "A");
            Clay.MakeConnection(s, this, "B");
            Clay.MakeConnection(s, this, "C");


            s["A"] = 2;

            Assert(SumR, 0);
            s["B"] = 3;
            Thread.Sleep(100);
            Assert(SumR, 5);

            s["C"] = 8;
            Thread.Sleep(100);
            Assert(MulR, 40);

            s["C"] = 4;
            Thread.Sleep(100);
            Assert(MulR, 20);


            s["A"] = 3;
            Thread.Sleep(100);
            Assert(SumR, 6);
            Assert(MulR, 24);

            s["B"] = 9;
            Thread.Sleep(100);
            Assert(SumR, 12);
            Assert(MulR, 48);
        }
Пример #8
0
        public override void Test()
        {
            int          Result  = 0;
            int          Result2 = 0;
            int          Result3 = 0;
            ResponseFunc f       = (RClay rc, object cp) => {
                int A = Result = rc.GetSignals <int>("X");
                int B = Result = rc.GetSignals <int>("Y");
                Result = A + B;
            };

            ResponseFunc f2 = (RClay rc, object cp) =>
            {
                Result2 = rc.GetSignals <int>("A");
            };

            ResponseFunc f3 = (RClay rc, object cp) =>
            {
                Result3 += rc.GetSignals <int>("A");
            };

            RClay R = new RClay(new Dictionary <string, object>()
            {
                { "Response", f },
                { "ConnectPoints", new List <Object> {
                      "X", "Y"
                  } }
            });

            RClay R2 = new RClay(new Dictionary <string, object> {
                { "Response", f2 },
                { "ConnectPoints", new List <Object> {
                      "A"
                  } }
            });

            RClay R3 = new RClay(new Dictionary <string, object> {
                { "Response", f3 },
                { "ConnectPoints", new List <Object> {
                      "A"
                  } }
            });

            Conduit con = Conduit.CreateLink(this, "X", R, "X");

            con.Connect(R, "Y");
            con.Connect(R2, "A");

            con.ParallelTrx = false;             //Disable parallel transmission

            Signal = 1;

            Assert(Result, 2);
            Assert(Result2, 1);
            Signal = 2;

            Assert(Result, 4);
            Assert(Result2, 2);


            //con.ParallelTrx = true; //Enable parallel transmission
            Signal = 3;
            Thread.Sleep(100);             //Wait

            Assert(Result, 6);
            Assert(Result2, 3);

            Conduit con2 = Conduit.CreateLink(con, "RANDOM");

            con2.Connect(R3, "A");
            con2.Connect(con, "CDE");


            Signal = 7;
            Thread.Sleep(100);             //Wait
            Assert(Result, 14);
            Assert(Result2, 7);
            Signal = 7;
            //No Bounce
            Assert(Result3, 7);
        }
Пример #9
0
        protected override void Run(string[] args)
        {
            var waiter = new AutoResetEvent(false);


            int data  = 0;
            var clay1 = new Starter();

            var f1 = new SignalFilter(new FilterAgr
            {
                Weight = 2
            });
            var f2 = new SignalFilter(new FilterAgr
            {
                Weight = 3
            });

            var f3 = new SignalFilter(new FilterAgr {
                Weight = 4
            });



            var clayx = new RClay(new RAgreement
            {
                SensorPoints = new List <object> {
                    "A", "B", "C"
                },
                Response = (center, clay, cp) => {
                    var A = center.GetSignal <int>("A");
                    var B = center.GetSignal <int>("B");
                    var C = center.GetSignal <int>("C");
                    data  = A + B + C;
                    waiter.Set();
                }
            });

            Conduit.CreateLink(
                new LinkDef(clay1, "OUT"),
                new LinkDef(f1, "IN"),
                new LinkDef(f2, "IN"),
                new LinkDef(f3, "IN")
                );

            Conduit.CreateLink(new LinkDef[] {
                new LinkDef(f1, "OUT"),
                new LinkDef(clayx, "A")
            });
            Conduit.CreateLink(new LinkDef[] {
                new LinkDef(f2, "OUT"),
                new LinkDef(clayx, "B")
            });
            Conduit.CreateLink(new LinkDef[] {
                new LinkDef(f3, "OUT"),
                new LinkDef(clayx, "C")
            });



            clay1.Test(5);

            waiter.WaitOne();
            Assert(data == 45, "Supposed to be 45");
        }
Пример #10
0
        public override void Test()
        {
            RClay other = new RClay();

            int          Result = 0;
            int          Inited = 0;
            ResponseFunc r      = (RClay rc, object cp) => {
                int A = rc.GetSignals <int>("A");
                int B = rc.GetSignals <int>("B");
                Result = A + B;
            };
            InitFunc i = (RClay rc) => { Inited++; };

            RClay c = new RClay(new Dictionary <string, object> {
                { "P1", 1 },
                { "P2", 2 },
                { "ConnectPoints", new List <object> {
                      "A", "B"
                  } },
                { "Response", r },
                { "Init", i }
            });

            c.onConnection(this, "A");
            c.onConnection(this, "B");

            c.onCommunication(this, "A", 1);
            //Make sure that if clay has not collected every signal
            //There will be no response
            Assert(Result, 0);

            c.onCommunication(this, "B", 2);

            Assert(Result, 3);

            //Randomly check Init already got called and got called once only
            Assert(Inited, 1);

            c.onCommunication(this, "A", 2);

            Assert(Result, 4);

            //Make sure signal from stranger does not count
            c.onCommunication(other, "A", 6);
            Assert(Result, 4);

            c.Stage = true;

            c.onCommunication(this, "B", 4);
            Assert(Result, 6);

            //Randomly check Init already got called and got called once only
            Assert(Inited, 1);

            c.onCommunication(this, "B", 7);
            //Make sure that Stage did clear all signals
            //And result should be the same as the previous
            Assert(Result, 6);

            //Assign information to B again
            c.onCommunication(this, "B", 8);
            // Make sure no change
            //And result should be the same as the previous
            Assert(Result, 6);

            c.onCommunication(this, "A", 8);
            Assert(Result, 16);

            c.onCommunication(this, "B", 1);
            //Make sure that all signals got cleared again
            //And the result is still the same because response has not been called
            Assert(Result, 16);
        }