コード例 #1
0
        public static void AssertJTokenCondition(JToken token, AssertCondition condition, string pathName)
        {
            switch (condition)
            {
            case AssertCondition.Empty:
                switch (token.Type)
                {
                case JTokenType.Array:
                    token.Values <object>().Should().BeEmpty($"{pathName} должен быть пустым массивом");
                    break;

                case JTokenType.String:
                    token.Value <string>().Should().BeEmpty($"Строка {pathName} должна быть пустой");
                    break;
                }

                break;

            case AssertCondition.NoEmpty:
                switch (token.Type)
                {
                case JTokenType.Array:
                    token.Values <object>().Should().NotBeEmpty($"{pathName} не должен быть пустым массивом");
                    break;

                case JTokenType.String:
                    token.Value <string>().Should().NotBeEmpty($"Строка {pathName} не должна быть пустой");
                    break;
                }

                break;
            }
        }
コード例 #2
0
ファイル: AgendaTests.cs プロジェクト: WoodMuleen/expergent
        public void TestAddProduction()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));

            AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");

            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);

            Agenda agenda = new Agenda();

            agenda.ConflictResolutionStrategy = new SalienceResolver();
            agenda.AddProduction(prod);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\TestAgenda.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 1, "Bad");
        }
コード例 #3
0
 public void ShouldNot(AssertCondition condition)
 {
     ShouldNot(condition, DefaultTimeout);
 }
コード例 #4
0
 public void ShouldNot(AssertCondition condition, int timeout)
 {
     Wait(() => !condition.Invoke(this),
          $"Timed out after {timeout / 1000} seconds while PollingHelper.Waiting for AssertCondition Not fulfilled: {condition}",
          timeout, Settings.WaitStrategy);
 }
コード例 #5
0
 public abstract void AssertCondition(AssertCondition condition);
コード例 #6
0
        public void RemoveProduction()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");

            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);
            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");

            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");

            rete.RemoveProduction(prod);

            Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions");

            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
コード例 #7
0
        public void NCCConditionTest()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");
            Variable w = new Variable("w");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));

            NCCCondition neg = new NCCCondition("C3", z, "color", "red");

            neg.ConditionType = ConditionType.NCC;
            //neg.IsPositive = false;
            //neg.IsNegative = false;
            neg.SubConditions.Add(new PositiveCondition("C4", z, "on", w));
            prod.AddConditionToLHS(neg);

            AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");

            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);

            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");
            NetworkPrinter printer = new NetworkPrinter();

            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\NCCTest.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }
            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
コード例 #8
0
 public override void AssertCondition(AssertCondition condition)
 {
     JTokenAssertion.AssertJTokenCondition(Token, condition, PathName);
 }
コード例 #9
0
ファイル: BuiltinsTests.cs プロジェクト: WoodMuleen/expergent
        public void ListTest2()
        {
            Production prod = new Production();

            prod.Label = "ListTest";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");
            Variable l = new Variable("l");
            Variable v = new Variable("v");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToLHS(new PositiveCondition("C4", x, "has virtue", l));
            prod.AddConditionToLHS(new PositiveCondition("C5", "virtues", "virtueList", v));
            prod.AddConditionToLHS(new FunctionCondition("C6", l, new FuncTerm("isInList", new isInList()), v));

            AssertCondition rhs = new AssertCondition("R1", x, "is", "good");

            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);

            Agenda agenda = new Agenda();

            agenda.ConflictResolutionStrategy = new SalienceResolver();
            agenda.AddProduction(prod);


            WME v1 = new WME("V1", "B1", "has virtue", "Calm");

            agenda.AddFact(v1);

            WME v2 = new WME("V2", "virtues", "virtueList", new string[] { "Calm", "Cool", "Collected" });

            agenda.AddFact(v2);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\ListTest2.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 1, "Bad");
        }
コード例 #10
0
        public void BasicOverrideTest()
        {
            Agenda agenda = new Agenda();

            agenda.ConflictResolutionStrategy = new SalienceResolver();

            Production prod = new Production();

            prod.Label = "Gold Customer";
            Variable customer  = new Variable("customer");
            Variable purchases = new Variable("purchases");

            prod.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            FunctionCondition gt = new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 10);

            gt.ConditionType = ConditionType.Function;
            prod.AddConditionToLHS(gt);
            AssertCondition rhs = new AssertCondition("R1", customer, "is", "gold");

            rhs.ConditionType = ConditionType.Assert;
            prod.AddConditionToRHS(rhs);
            agenda.AddProduction(prod);

            Production prod1 = new Production();

            prod1.Label = "Platinum Customer";

            prod1.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            FunctionCondition gt1 = new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 20);

            gt1.ConditionType = ConditionType.Function;
            prod1.AddConditionToLHS(gt1);
            AssertCondition rhs1 = new AssertCondition("R1", customer, "is", "Platinum");

            rhs.ConditionType = ConditionType.Assert;
            prod1.AddConditionToRHS(rhs1);
            agenda.AddProduction(prod1);

            Override me = new Override();

            me.Winner = "Platinum Customer";
            me.Loser  = "Gold Customer";

            agenda.AddOverride(me);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "joe";
            wme1.Fields[1] = "purchases";
            wme1.Fields[2] = "1";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "ted";
            wme2.Fields[1] = "purchases";
            wme2.Fields[2] = "10";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "ed";
            wme3.Fields[1] = "purchases";
            wme3.Fields[2] = "11";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "phil";
            wme4.Fields[1] = "purchases";
            wme4.Fields[2] = "18";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "mary";
            wme5.Fields[1] = "purchases";
            wme5.Fields[2] = "22";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "jane";
            wme6.Fields[1] = "purchases";
            wme6.Fields[2] = "25";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "fred";
            wme7.Fields[1] = "purchases";
            wme7.Fields[2] = "50";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "harry";
            wme8.Fields[1] = "purchases";
            wme8.Fields[2] = "55";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "jon";
            wme9.Fields[1] = "purchases";
            wme9.Fields[2] = "99";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\BasicOverrideTest.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 5, "Bad");
        }