public void Equals() { IRule <int> rule1 = RuleMaker.Is(10).Or(20).Or(30); IRule <int> rule2 = RuleMaker.Is(10).Or(20).Or(30); Assert.IsTrue(rule1.Equals(rule2)); Assert.IsTrue(rule2.Equals(rule1)); // Different order means a different rule because the evaluation may stop in different point. // E.g. if the second OR is true then it does not continue. So both rules although giving the same result will // be evaluated differently. rule2 = RuleMaker.Is(10).Or(30).Or(20); Assert.IsFalse(rule1.Equals(rule2)); rule1 = RuleMaker.Is(10).And(20).And(30); rule2 = RuleMaker.Is(10).And(20).And(30); Assert.IsTrue(rule1.Equals(rule2)); Assert.IsTrue(rule2.Equals(rule1)); rule2 = RuleMaker.Is(10).And(30).And(20); Assert.IsFalse(rule1.Equals(rule2)); rule1 = RuleMaker.Is(10).Not(); rule2 = RuleMaker.Is(10).Not(); Assert.IsTrue(rule1.Equals(rule2)); rule1 = RuleMaker.Is(10).Not(); rule2 = RuleMaker.Is(20).Not(); Assert.IsFalse(rule1.Equals(rule2)); rule1 = RuleMaker.Anything <int>(); rule2 = RuleMaker.Anything <int>(); Assert.IsTrue(rule1.Equals(rule2)); rule1 = RuleMaker.Nothing <int>(); rule2 = RuleMaker.Nothing <int>(); Assert.IsTrue(rule1.Equals(rule2)); }
public void IsSubruleOf() { IRule <int> rule1 = RuleMaker.Is(1) | RuleMaker.Is(2); IRule <int> rule2 = RuleMaker.Is(1) | RuleMaker.Is(2) | RuleMaker.Is(3); Assert.IsTrue(rule1.IsSubruleOf(rule2)); Assert.IsFalse(rule2.IsSubruleOf(rule1)); // Two same rules. Assert.IsTrue(rule1.IsSubruleOf(rule1)); Assert.IsTrue(rule1.IsSubruleOf(RuleMaker.Anything <int>())); Assert.IsFalse(rule1.IsSubruleOf(RuleMaker.Nothing <int>())); Assert.IsTrue(RuleMaker.Anything <int>().IsSubruleOf(RuleMaker.Anything <int>())); Assert.IsFalse(RuleMaker.Anything <int>().IsSubruleOf(RuleMaker.Nothing <int>())); Assert.IsFalse(RuleMaker.Nothing <int>().IsSubruleOf(RuleMaker.Anything <int>())); }