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'"); }
public void FactBaseCloning() { FactBase fb = new FactBase(); PopulateFactBase(fb); FactBase clone = (FactBase)fb.Clone(); Assert.AreEqual(fb.Count, clone.Count, "Same number of facts"); Fact jqdSpending = clone.GetFact("JQD Spending"); Assert.AreEqual("JQD Spending", jqdSpending.Label, "Correct fact label"); int countBefore = clone.Count; Assert.IsTrue(clone.Retract(jqdSpending), "Retracted 'JQD Spending'"); Assert.AreEqual(countBefore - 1, clone.Count, "Count after retraction"); Assert.IsFalse(clone.Exists(jqdSpending), "'JQD Spending' really retracted"); Assert.IsTrue(fb.Exists(jqdSpending), "'JQD Spending' still in original"); Atom filter = new Atom("spending", new Variable("name"), new Function(Function.FunctionResolutionType.NxBRE, "foo", null, "GreaterThan", "5000"), new Individual("previous year")); Assert.AreEqual(1, CountEnumerator(fb.Select(filter, null)), "Query on the original"); Assert.AreEqual(0, CountEnumerator(clone.Select(filter, null)), "Query on the clone"); }
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'"); }
public void FactBaseCloning() { FactBase fb = new FactBase(); PopulateFactBase(fb); FactBase clone = (FactBase)fb.Clone(); Assert.AreEqual(fb.Count, clone.Count, "Same number of facts"); Fact jqdSpending = clone.GetFact("JQD Spending"); Assert.AreEqual("JQD Spending", jqdSpending.Label, "Correct fact label"); int countBefore = clone.Count; Assert.IsTrue(clone.Retract(jqdSpending), "Retracted 'JQD Spending'"); Assert.AreEqual(countBefore-1, clone.Count, "Count after retraction"); Assert.IsFalse(clone.Exists(jqdSpending), "'JQD Spending' really retracted"); Assert.IsTrue(fb.Exists(jqdSpending), "'JQD Spending' still in original"); Atom filter = new Atom("spending", new Variable("name"), new Function(Function.FunctionResolutionType.NxBRE, "foo", null, "GreaterThan", "5000"), new Individual("previous year")); Assert.AreEqual(1, CountEnumerator(fb.Select(filter, null)), "Query on the original"); Assert.AreEqual(0, CountEnumerator(clone.Select(filter, null)), "Query on the clone"); }