Example #1
0
        public void ExcludeFactsFromSelection()
        {
            FactBase fb = new FactBase();

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                             new Individual("Peter Miller"),
                                             new Individual(5000),
                                             new Individual("previous year"))), "Assert 'P.Miller Spending'");

            Fact jqdSpending = new Fact("JQD Spending",
                                        "spending",
                                        new Individual("John Q.Clone Doe"),
                                        new Individual(7000),
                                        new Individual("previous year"));

            Assert.IsTrue(fb.Assert(jqdSpending), "Assert 'JQD Spending'");

            Atom filter = new Atom("spending",
                                   new Variable("name"),
                                   new Function(Function.FunctionResolutionType.NxBRE, "foo", null, "GreaterThanEqualTo", "5000"),
                                   new Individual("previous year"));

            Assert.AreEqual(2, CountEnumerator(fb.Select(filter, null)), "Query with NxBRE function and no fact exclusion");

            IList <Fact> excludedFacts = new List <Fact>();

            excludedFacts.Add(jqdSpending);

            Assert.AreEqual(1, CountEnumerator(fb.Select(filter, excludedFacts)), "Query with NxBRE function with fact exclusion");
        }
Example #2
0
        public void FactBaseAssertRetract()
        {
            FactBase fb = new FactBase();

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                             new Individual("Peter Miller"),
                                             new Individual("min(5000,EUR)"),
                                             new Individual("previous year"))), "Assert 'P.Miller Spending'");

            Assert.IsTrue(fb.Assert(new Fact("JQD Spending",
                                             "spending",
                                             new Individual("John Q.Clone Doe"),
                                             new Individual("min(7000,EUR)"),
                                             new Individual("previous year"))), "Assert 'JQD Spending'");

            Assert.IsNotNull(fb.GetFact("JQD Spending"), "Exist 'JQD Spending'");

            Assert.IsFalse(fb.Assert(fact3bis), "Assert fact3bis");
            Assert.IsTrue(fb.Assert(factX), "Assert factX");

            Fact jqdSpending = fb.GetFact("JQD Spending");

            Assert.IsTrue(fb.Exists(jqdSpending));
            Assert.IsTrue(fb.Retract(jqdSpending));
            Assert.IsFalse(fb.Exists(jqdSpending));

            Assert.IsNull(fb.GetFact("JQD Spending"), "Get Retracted 'JQD Spending'");
        }
Example #3
0
        public void FactBaseAssertModify()
        {
            FactBase fb = new FactBase();

            Fact spendingPM1 = new Fact("Spending of Peter Miller",
                                        "spending",
                                        new Individual("Peter Miller"),
                                        new Individual("min(5000,EUR)"),
                                        new Individual("previous year"));

            Assert.IsTrue(fb.Assert(spendingPM1), "Assert 'P.Miller Spending' v1");
            Assert.IsFalse(fb.Assert(spendingPM1), "Can not assert 'P.Miller Spending' v1 twice!");
            Assert.IsTrue(fb.Exists(spendingPM1), "Exists 'P.Miller Spending' v1");

            Fact spendingJQD = new Fact("Spending of John Q. Doe",
                                        "spending",
                                        new Individual("John Q.Clone Doe"),
                                        new Individual("min(7000,EUR)"),
                                        new Individual("previous year"));

            Assert.IsTrue(fb.Assert(spendingJQD), "Assert 'JQD Spending'");

            Fact spendingPM2 = new Fact("spending",
                                        new Individual("Peter Miller"),
                                        new Individual("min(9999,EUR)"),
                                        new Individual("previous year"));

            Assert.IsTrue(fb.Modify(spendingPM1, spendingPM2), "Modify 'P.Miller Spending' v1 to v2");
            Assert.IsNotNull(fb.GetFact(spendingPM1.Label), "(1) Label has been maintained");
            Assert.AreEqual(2, fb.Count, "(1) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(1) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(1) Exists 'P.Miller Spending' v2");
            Assert.IsTrue(fb.Exists(spendingJQD), "(1) Exists 'JQD Spending'");

            Assert.IsFalse(fb.Modify(spendingPM1, spendingPM2), "Can not modify an inexistant fact");
            Assert.AreEqual(2, fb.Count, "(2) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(2) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(2) Exists 'P.Miller Spending' v2");
            Assert.IsTrue(fb.Exists(spendingJQD), "(2) Exists 'JQD Spending'");

            Assert.IsTrue(fb.Modify(spendingPM2, spendingPM2), "Can modify a fact to itself");
            Assert.AreEqual(2, fb.Count, "(3) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(3) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(3) Exists 'P.Miller Spending' v2");
            Assert.IsTrue(fb.Exists(spendingJQD), "(3) Exists 'JQD Spending'");

            Assert.IsTrue(fb.Modify(spendingJQD, spendingPM2), "Modify 'JQD Spending' to 'P.Miller Spending' v2");
            Assert.IsNotNull(fb.GetFact(spendingJQD.Label), "(4) Label has been maintained");
            Assert.AreEqual(1, fb.Count, "(4) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(4) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(4) Exists 'P.Miller Spending' v2");
            Assert.IsFalse(fb.Exists(spendingJQD), "(4) Not Exists 'JQD Spending'");
        }
Example #4
0
        private int RunStrictTypingFactBaseTest(bool strictTyping)
        {
            FactBase fb = new FactBase();

            fb.strictTyping = strictTyping;

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                             new Individual("foo"),
                                             new Individual(7000))), "Assert 'foo Spending'");

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                             new Individual("bar"),
                                             new Individual("7000"))), "Assert 'bar Spending'");

            Atom filter = new Atom("spending",
                                   new Variable("name"),
                                   new Individual("7000"));

            return(CountEnumerator(fb.Select(filter, null)));
        }
Example #5
0
        private void PopulateFactBase(FactBase fb)
        {
            Assert.IsTrue(fb.Assert(new Fact("spending",
                                             new Individual("foo"),
                                             new Individual(7000))), "Assert 'foo Spending'");

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                             new Individual("Peter Miller"),
                                             new Individual(5000),
                                             new Individual("previous year"))), "Assert 'P.Miller Spending'");

            Assert.IsTrue(fb.Assert(new Fact("JQD Spending",
                                             "spending",
                                             new Individual("John Q.Clone Doe"),
                                             new Individual(7000),
                                             new Individual("previous year"))), "Assert 'JQD Spending'");

            Assert.IsTrue(fb.Assert(new Fact("lending",
                                             new Individual("John Q.Clone Doe"),
                                             new Individual(7000),
                                             new Individual("previous year"))), "Assert 'JQD Lending'");
        }
Example #6
0
        private int RunStrictTypingFactBaseTest(bool strictTyping)
        {
            FactBase fb = new FactBase();
            fb.strictTyping = strictTyping;

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                                        new Individual("foo"),
                                                        new Individual(7000))), "Assert 'foo Spending'");

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                                        new Individual("bar"),
                                                        new Individual("7000"))), "Assert 'bar Spending'");

            Atom filter = new Atom("spending",
                                   new Variable("name"),
                                   new Individual("7000"));

            return CountEnumerator(fb.Select(filter, null));
        }
Example #7
0
        private void PopulateFactBase(FactBase fb)
        {
            Assert.IsTrue(fb.Assert(new Fact("spending",
                                                        new Individual("foo"),
                                                        new Individual(7000))), "Assert 'foo Spending'");

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                                        new Individual("Peter Miller"),
                                                        new Individual(5000),
                                                        new Individual("previous year"))), "Assert 'P.Miller Spending'");

            Assert.IsTrue(fb.Assert(new Fact("JQD Spending",
                                                           "spending",
                                                        new Individual("John Q.Clone Doe"),
                                                        new Individual(7000),
                                                        new Individual("previous year"))), "Assert 'JQD Spending'");

            Assert.IsTrue(fb.Assert(new Fact("lending",
                                                        new Individual("John Q.Clone Doe"),
                                                        new Individual(7000),
                                                        new Individual("previous year"))), "Assert 'JQD Lending'");
        }
Example #8
0
        public void FactBaseAssertRetract()
        {
            FactBase fb = new FactBase();

            Assert.IsTrue(fb.Assert(new Fact("spending",
                            new Individual("Peter Miller"),
                            new Individual("min(5000,EUR)"),
                            new Individual("previous year"))), "Assert 'P.Miller Spending'");

            Assert.IsTrue(fb.Assert(new Fact("JQD Spending",
                               "spending",
                            new Individual("John Q.Clone Doe"),
                            new Individual("min(7000,EUR)"),
                            new Individual("previous year"))), "Assert 'JQD Spending'");

            Assert.IsNotNull(fb.GetFact("JQD Spending"), "Exist 'JQD Spending'");

            Assert.IsFalse(fb.Assert(fact3bis), "Assert fact3bis");
            Assert.IsTrue(fb.Assert(factX), "Assert factX");

            Fact jqdSpending = fb.GetFact("JQD Spending");
            Assert.IsTrue(fb.Exists(jqdSpending));
            Assert.IsTrue(fb.Retract(jqdSpending));
            Assert.IsFalse(fb.Exists(jqdSpending));

            Assert.IsNull(fb.GetFact("JQD Spending"), "Get Retracted 'JQD Spending'");
        }
Example #9
0
        public void FactBaseAssertModify()
        {
            FactBase fb = new FactBase();

            Fact spendingPM1 = new Fact("Spending of Peter Miller",
                                        "spending",
                                               new Individual("Peter Miller"),
                                               new Individual("min(5000,EUR)"),
                                               new Individual("previous year"));

            Assert.IsTrue(fb.Assert(spendingPM1), "Assert 'P.Miller Spending' v1");
            Assert.IsFalse(fb.Assert(spendingPM1), "Can not assert 'P.Miller Spending' v1 twice!");
            Assert.IsTrue(fb.Exists(spendingPM1), "Exists 'P.Miller Spending' v1");

            Fact spendingJQD = new Fact("Spending of John Q. Doe",
                                        "spending",
                                            new Individual("John Q.Clone Doe"),
                                            new Individual("min(7000,EUR)"),
                                            new Individual("previous year"));

            Assert.IsTrue(fb.Assert(spendingJQD), "Assert 'JQD Spending'");

            Fact spendingPM2 = new Fact("spending",
                                               new Individual("Peter Miller"),
                                               new Individual("min(9999,EUR)"),
                                               new Individual("previous year"));

            Assert.IsTrue(fb.Modify(spendingPM1, spendingPM2), "Modify 'P.Miller Spending' v1 to v2");
            Assert.IsNotNull(fb.GetFact(spendingPM1.Label), "(1) Label has been maintained");
            Assert.AreEqual(2, fb.Count, "(1) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(1) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(1) Exists 'P.Miller Spending' v2");
            Assert.IsTrue(fb.Exists(spendingJQD), "(1) Exists 'JQD Spending'");

            Assert.IsFalse(fb.Modify(spendingPM1, spendingPM2), "Can not modify an inexistant fact");
            Assert.AreEqual(2, fb.Count, "(2) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(2) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(2) Exists 'P.Miller Spending' v2");
            Assert.IsTrue(fb.Exists(spendingJQD), "(2) Exists 'JQD Spending'");

            Assert.IsTrue(fb.Modify(spendingPM2, spendingPM2), "Can modify a fact to itself");
            Assert.AreEqual(2, fb.Count, "(3) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(3) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(3) Exists 'P.Miller Spending' v2");
            Assert.IsTrue(fb.Exists(spendingJQD), "(3) Exists 'JQD Spending'");

            Assert.IsTrue(fb.Modify(spendingJQD, spendingPM2), "Modify 'JQD Spending' to 'P.Miller Spending' v2");
            Assert.IsNotNull(fb.GetFact(spendingJQD.Label), "(4) Label has been maintained");
            Assert.AreEqual(1, fb.Count, "(4) FactBase size");
            Assert.IsFalse(fb.Exists(spendingPM1), "(4) Not Exists 'P.Miller Spending' v1");
            Assert.IsTrue(fb.Exists(spendingPM2), "(4) Exists 'P.Miller Spending' v2");
            Assert.IsFalse(fb.Exists(spendingJQD), "(4) Not Exists 'JQD Spending'");
        }
Example #10
0
        public void ExcludeFactsFromSelection()
        {
            FactBase fb = new FactBase();

            Assert.IsTrue(fb.Assert(new Fact("spending",
                                                        new Individual("Peter Miller"),
                                                        new Individual(5000),
                                                        new Individual("previous year"))), "Assert 'P.Miller Spending'");

            Fact jqdSpending = new Fact("JQD Spending",
                                                   "spending",
                                                new Individual("John Q.Clone Doe"),
                                                new Individual(7000),
                                                new Individual("previous year"));

            Assert.IsTrue(fb.Assert(jqdSpending), "Assert 'JQD Spending'");

            Atom filter = new Atom("spending",
                                   new Variable("name"),
                                   new Function(Function.FunctionResolutionType.NxBRE, "foo", null, "GreaterThanEqualTo", "5000"),
                                   new Individual("previous year"));

            Assert.AreEqual(2, CountEnumerator(fb.Select(filter, null)), "Query with NxBRE function and no fact exclusion");

            IList<Fact> excludedFacts = new List<Fact>();
            excludedFacts.Add(jqdSpending);

            Assert.AreEqual(1, CountEnumerator(fb.Select(filter, excludedFacts)), "Query with NxBRE function with fact exclusion");
        }