public void ConjunctionTest() { var prob = new Problem("ConjunctionTest"); var p = (Proposition)"p"; var q = (Proposition)"q"; Assert.IsTrue(ReferenceEquals(p, prob.Conjunction(p, p))); var conj = prob.Conjunction(p, q); var reverseConj = prob.Conjunction(q, p); Assert.IsTrue(ReferenceEquals(conj, reverseConj)); for (int i = 0; i < 100; i++) { var s = prob.Solve(); Console.WriteLine(s.Model); Assert.IsTrue(s[conj] == (s[p] & s[q])); } }
public void SumConditionTest() { var problem = new Problem("test"); var dom = new FloatDomain("signed unit", -1, 1); var p = (Proposition)"p"; var x = (FloatVariable)dom.Instantiate("x", problem, p); var q = (Proposition)"q"; var y = (FloatVariable)dom.Instantiate("y", problem, q); var sum = x + y; Assert.IsTrue(ReferenceEquals(sum.Condition, problem.Conjunction(p, q))); for (int i = 0; i < 100; i++) { var s = problem.Solve(); Console.WriteLine(s.Model); Assert.AreEqual(sum.IsDefinedInInternal(s), x.IsDefinedInInternal(s) & y.IsDefinedInInternal(s)); if (sum.IsDefinedInInternal(s)) { Assert.IsTrue(Math.Abs(sum.Value(s) - (x.Value(s) + y.Value(s))) < 0.00001f); } } }