Ejemplo n.º 1
0
        public ImplicationRule CreateImplicationRuleEntity(string implicationRule)
        {
            var implicationRuleStrings = _implicationRuleParser.ExtractStatementParts(implicationRule);
            var ifStatement            = implicationRuleStrings.IfStatement;
            var thenStatement          = implicationRuleStrings.ThenStatement;
            var ifStatementParts       = _implicationRuleParser.ParseImplicationRule(ref ifStatement);
            var thenStatementParts     = _implicationRuleParser.ParseStatementCombination(thenStatement);

            var ifStatementCombination = new List <StatementCombination>();

            foreach (var ifStatementPart in ifStatementParts)
            {
                var ifUnaryStatementStrings = _implicationRuleParser.ParseStatementCombination(ifStatementPart);
                var ifUnaryStatements       = ifUnaryStatementStrings
                                              .Select(ifUnaryStatementString => _implicationRuleParser.ParseUnaryStatement(ifUnaryStatementString))
                                              .ToList();
                ifStatementCombination.Add(new StatementCombination(ifUnaryStatements));
            }

            var thenUnaryStatements = thenStatementParts
                                      .Select(thenStatementPart => _implicationRuleParser.ParseUnaryStatement(thenStatementPart))
                                      .ToList();
            var thenStatementCombination = new StatementCombination(thenUnaryStatements);

            return(new ImplicationRule(ifStatementCombination, thenStatementCombination));
        }
        public void ThenStatement_GetterWorksProperly()
        {
            // Act
            StatementCombination actualUnaryStatement = _implicationRule.ThenStatement;

            // Assert
            Assert.AreEqual(_thenUnaryStatement, actualUnaryStatement);
        }
Ejemplo n.º 3
0
        public void UnaryStatementsGetterReturnsValue()
        {
            // Arrange
            List <UnaryStatement> expectedUnaryStatements = new List <UnaryStatement>
            {
                new UnaryStatement("A", ComparisonOperation.Equal, "10"),
                new UnaryStatement("B", ComparisonOperation.Equal, "20")
            };
            StatementCombination statementCombination = new StatementCombination(expectedUnaryStatements);

            // Act
            List <UnaryStatement> actualUnaryStatements = statementCombination.UnaryStatements;

            //
            Assert.AreEqual(expectedUnaryStatements, actualUnaryStatements);
        }
Ejemplo n.º 4
0
        public void CreateImplicationRuleEntity_ReturnsImplicationRule()
        {
            // Arrange
            string ifStatementPart   = "(A=a|(B=b&C=c))";
            string thenStatementPart = "(D=d)";
            string implicationRule   = $"IF{ifStatementPart}THEN{thenStatementPart}";
            ImplicationRuleStrings implicationRuleStrings = new ImplicationRuleStrings(ifStatementPart, thenStatementPart);

            _implicationRuleParser.Expect(x => x.ExtractStatementParts(implicationRule)).Return(implicationRuleStrings);

            // (A=a|(B=b&C=c))
            List <StatementCombination> ifStatementCombinations = new List <StatementCombination>
            {
                new StatementCombination(new List <UnaryStatement>
                {
                    new UnaryStatement("A", ComparisonOperation.Equal, "a")
                }),
                new StatementCombination(new List <UnaryStatement>
                {
                    new UnaryStatement("B", ComparisonOperation.Equal, "b"),
                    new UnaryStatement("C", ComparisonOperation.Equal, "c")
                })
            };
            // (D=d)
            StatementCombination thenStatementCombination = new StatementCombination(new List <UnaryStatement>
            {
                new UnaryStatement("D", ComparisonOperation.Equal, "d")
            });
            ImplicationRule expectedImplicationRule = new ImplicationRule(ifStatementCombinations, thenStatementCombination);

            List <string> ifStatementParts = new List <string> {
                "A=a", "B=b&C=c"
            };

            _implicationRuleParser.Expect(irp => irp.ParseImplicationRule(ref ifStatementPart))
            .Return(ifStatementParts);
            List <string> thenStatementParts = new List <string> {
                "D=d"
            };

            _implicationRuleParser.Expect(irp => irp.ParseStatementCombination(thenStatementPart))
            .Return(thenStatementParts);

            List <string> aIfUnaryStatementStrings = new List <string> {
                "A=a"
            };
            List <string> bcIfUnaryStatementStrings = new List <string> {
                "B=b", "C=c"
            };

            _implicationRuleParser.Expect(irp => irp.ParseStatementCombination("A=a")).Return(aIfUnaryStatementStrings);
            _implicationRuleParser.Expect(irp => irp.ParseStatementCombination("B=b&C=c")).Return(bcIfUnaryStatementStrings);

            UnaryStatement aUnaryStatement = new UnaryStatement("A", ComparisonOperation.Equal, "a");
            UnaryStatement bUnaryStatement = new UnaryStatement("B", ComparisonOperation.Equal, "b");
            UnaryStatement cUnaryStatement = new UnaryStatement("C", ComparisonOperation.Equal, "c");
            UnaryStatement dUnaryStatement = new UnaryStatement("D", ComparisonOperation.Equal, "d");

            _implicationRuleParser.Expect(irp => irp.ParseUnaryStatement("A=a")).Return(aUnaryStatement);
            _implicationRuleParser.Expect(irp => irp.ParseUnaryStatement("B=b")).Return(bUnaryStatement);
            _implicationRuleParser.Expect(irp => irp.ParseUnaryStatement("C=c")).Return(cUnaryStatement);
            _implicationRuleParser.Expect(irp => irp.ParseUnaryStatement("D=d")).Return(dUnaryStatement);

            // Act
            ImplicationRule actualImplicationRule = _implicationRuleCreator.CreateImplicationRuleEntity(implicationRule);

            // Assert
            Assert.IsTrue(ObjectComparer.ImplicationRulesAreEqual(expectedImplicationRule, actualImplicationRule));
        }