public void Accept() { var termA = new FuzzyTerm("TermA", new MembershipFunction()); var termB = new FuzzyTerm("TermB", new MembershipFunction()); var varA = new FuzzyVariable("Variable A", null, termA); var varB = new FuzzyVariable("Variable B", null, termB); var mocks = new MockRepository(); var visitor = mocks.StrictMock<IExpressionVisitor<int>>(); var sut = new FuzzyImplication(new ValueExpression(varA, termA), new ValueExpression(varB, termB)); Expect.Call(visitor.Visit(sut)).Return(42); mocks.ReplayAll(); var result = sut.Accept(visitor); Assert.AreEqual(42, result); mocks.VerifyAll(); }
public void ComplexExpression() { var A = new FuzzyVariable("A", new NumericVariable("a")); var B = new FuzzyVariable("B", new NumericVariable("b")); var C = new FuzzyVariable("C", new NumericVariable("c")); var x = new FuzzyTerm("x", new MembershipFunction()); var y = new FuzzyTerm("y", new MembershipFunction()); var z = new FuzzyTerm("z", new MembershipFunction()); var ruleExpr = new FuzzyImplication( new OrExpression( new NotExpression( new AndExpression( new ValueExpression(A, x), new ValueExpression(B, y) ) ), new AndExpression( new ValueExpression(A, y), new ValueExpression(B, x) ) ), new ValueExpression(C, z) ); var sut = new GetInvolvedVariables(); var result = sut.Visit(ruleExpr); Assert.AreEqual(3, result.Count); Assert.IsTrue(result.Contains(A)); Assert.IsTrue(result.Contains(B)); Assert.IsTrue(result.Contains(C)); result = ruleExpr.Accept(sut); Assert.AreEqual(3, result.Count); Assert.IsTrue(result.Contains(A)); Assert.IsTrue(result.Contains(B)); Assert.IsTrue(result.Contains(C)); }
public void VisitRule() { var valueExpr1 = new ValueExpression( new FuzzyVariable("MyFuzzyVariable1", new NumericVariable("MyNumVariable1")), new FuzzyTerm("MyTerm1", new MembershipFunction())); var valueExpr2 = new ValueExpression( new FuzzyVariable("MyFuzzyVariable2", new NumericVariable("MyNumVariable2")), new FuzzyTerm("MyTerm2", new MembershipFunction())); var ruleExpr = new FuzzyImplication(valueExpr1, valueExpr2); var sut = new ToStringVisitor(); var result = sut.Visit(ruleExpr); Assert.AreEqual("MyFuzzyVariable1=MyTerm1 => MyFuzzyVariable2=MyTerm2", result); result = ruleExpr.Accept(sut); Assert.AreEqual("MyFuzzyVariable1=MyTerm1 => MyFuzzyVariable2=MyTerm2", result); }
public void VisitRule() { var variable1 = new FuzzyVariable("MyFuzzyVariable1", new NumericVariable("MyNumVariable1")); var variable2 = new FuzzyVariable("MyFuzzyVariable2", new NumericVariable("MyNumVariable2")); var valueExpr1 = new ValueExpression( variable1, new FuzzyTerm("MyTerm1", new MembershipFunction())); var valueExpr2 = new ValueExpression( variable2, new FuzzyTerm("MyTerm2", new MembershipFunction())); var ruleExpr = new FuzzyImplication(valueExpr1, valueExpr2); var sut = new GetInvolvedVariables(); var result = sut.Visit(ruleExpr); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(variable1)); Assert.IsTrue(result.Contains(variable2)); result = ruleExpr.Accept(sut); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(variable1)); Assert.IsTrue(result.Contains(variable2)); }
public void ComplexExpression() { var A = new FuzzyVariable("A", new NumericVariable("a")); var B = new FuzzyVariable("B", new NumericVariable("b")); var C = new FuzzyVariable("C", new NumericVariable("c")); var x = new FuzzyTerm("x", new MembershipFunction()); var y = new FuzzyTerm("y", new MembershipFunction()); var z = new FuzzyTerm("z", new MembershipFunction()); var ruleExpr = new FuzzyImplication( new OrExpression( new NotExpression( new AndExpression( new ValueExpression(A, x), new ValueExpression(B, y) ) ), new AndExpression( new ValueExpression(A, y), new ValueExpression(B, x) ) ), new ValueExpression(C, z) ); var sut = new ToStringVisitor(); var result = sut.Visit(ruleExpr); Assert.AreEqual("!( A=x && B=y ) || ( A=y && B=x ) => C=z", result); result = ruleExpr.Accept(sut); Assert.AreEqual("!( A=x && B=y ) || ( A=y && B=x ) => C=z", result); }