Ejemplo n.º 1
0
        public void GetLinguisticVariables_ReturnsLinguisticVariablesList()
        {
            // Arrange
            var expectedLinguisticVariables = Optional <Dictionary <int, LinguisticVariable> > .For(PrepareExpectedLinguisticVariables());

            // Act
            var actualLinguisticVariables = _linguisticVariableManager.GetLinguisticVariables(_profileName);

            // Assert
            Assert.IsTrue(actualLinguisticVariables.IsPresent);
            Assert.AreEqual(expectedLinguisticVariables.Value.Count, actualLinguisticVariables.Value.Count);
            for (var i = 1; i <= actualLinguisticVariables.Value.Count; i++)
            {
                Assert.IsTrue(ObjectComparer.LinguisticVariablesAreEqual(expectedLinguisticVariables.Value[i], actualLinguisticVariables.Value[i]));
            }
        }
        public void CreateLinguisticVariableEntity_ReturnsCorrectLinguisticVariable()
        {
            // Arrange
            List <double> firstFunctionValues = new List <double> {
                0, 20, 20, 30
            };
            List <double> secondFunctionValues = new List <double> {
                50, 60, 60, 80
            };
            List <MembershipFunctionStrings> membershipFunctionStringsList = new List <MembershipFunctionStrings>
            {
                new MembershipFunctionStrings("Cold", "Trapezoidal", firstFunctionValues),
                new MembershipFunctionStrings("Hot", "Trapezoidal", secondFunctionValues)
            };
            string linguisticVariable            = "Water:Initial:[Cold:Trapezoidal:(0,20,20,30)|Hot:Trapezoidal:(50,60,60,80)]";
            var    linguisticVariableStrings     = new LinguisticVariableStrings("Water", "Initial", membershipFunctionStringsList);
            var    linguisticVariableStringsList = new List <LinguisticVariableStrings> {
                linguisticVariableStrings
            };

            _linguisticVariableParserMock.Expect(x => x.ParseLinguisticVariable(linguisticVariable)).Return(linguisticVariableStringsList);

            var firstMembershipFunction  = new TrapezoidalMembershipFunction("Cold", 0, 20, 20, 30);
            var secondMembershipFunction = new TrapezoidalMembershipFunction("Hot", 50, 60, 60, 80);

            _membershipFunctionCreatorMock.Expect(x => x.CreateMembershipFunctionEntity(MembershipFunctionType.Trapezoidal, "Cold", firstFunctionValues))
            .Return(firstMembershipFunction);
            _membershipFunctionCreatorMock.Expect(x => x.CreateMembershipFunctionEntity(MembershipFunctionType.Trapezoidal, "Hot", secondFunctionValues))
            .Return(secondMembershipFunction);

            var expectedLinguisticVariable = new LinguisticVariable(
                "Water",
                new MembershipFunctionList {
                firstMembershipFunction, secondMembershipFunction
            },
                true);

            // Act
            var actualLinguisticVariables = _linguisticVariableCreator.CreateLinguisticVariableEntities(linguisticVariable);

            // Assert
            Assert.AreEqual(1, actualLinguisticVariables.Count);
            Assert.IsTrue(ObjectComparer.LinguisticVariablesAreEqual(expectedLinguisticVariable, actualLinguisticVariables[0]));
        }