internal void Build_WithComplexCondition_ReturnsExpectedFuzzyRule() { // Arrange var waterTemp = StubLinguisticVariableFactory.WaterTemp(); // Act var rule1 = new FuzzyRuleBuilder("Rule1") .If(ConditionBuilder .If(waterTemp.Is("cold")) .And(waterTemp.Not("freezing")) .Or(waterTemp.Not("frozen"))) .And(ConditionBuilder .If(waterTemp.Is("warm")) .And(waterTemp.Not("hot")) .Or(waterTemp.Not("boiling"))) .And(ConditionBuilder .If(waterTemp.Is("frozen")) .And(waterTemp.Is("warm"))) .Then(waterTemp.Not("frozen")) .Build(); var dataPoint = new DataPoint(waterTemp.Subject, 20); var data = new Dictionary <Label, DataPoint> { { dataPoint.Variable, dataPoint } }; var result = rule1.Evaluate(data, new FuzzyEvaluator()); var temp = waterTemp.GetState(2); // Assert //Assert.Equal(new FuzzyState("warm"), temp); //Assert.True(result); }
internal void Evaluate_ValidRuleAndConditions_ReturnsExpectedFuzzyOutput() { // Arrange var waterTemp = StubLinguisticVariableFactory.WaterTemp(); var fanSpeed = StubLinguisticVariableFactory.PumpSpeed(); var fuzzyRule = new FuzzyRuleBuilder(PumpSpeedRule.Rule0) .If(ConditionBuilder.If(waterTemp.Is(WaterTemp.Frozen))) .Or(ConditionBuilder.If(waterTemp.Is(WaterTemp.Freezing))) .Then(fanSpeed.Is(PumpSpeed.Off)) .Build(); var dataPoint = new DataPoint(waterTemp.Subject, 0); var data = new Dictionary <Label, DataPoint> { { dataPoint.Variable, dataPoint } }; // Act var result = fuzzyRule.Evaluate(data, new FuzzyEvaluator()); // Assert Assert.Equal(fanSpeed.Subject, result[0].Subject); Assert.Equal(fanSpeed.GetState(0), result[0].State); Assert.Equal(UnitInterval.One(), result[0].FiringStrength); Assert.Equal(fanSpeed.GetSet(PumpSpeed.Off), result[0].OutputFunction); }