Пример #1
0
        public void Replace_ReplacingExistingBoundVariableInComplexExpression_ShouldReturnTrueForChildrenContainingReplacedVariable()
        {
            // Arrange
            char variableToBeReplaced = 'w';

            List <char> variablesSetOne = new List <char>()
            {
                'u',
                variableToBeReplaced
            };

            // Does not contain the replacement variable
            List <char> variablesSetTwo = new List <char>()
            {
                'v',
                'x'
            };

            Predicate predicateWithReplacementVariable = new Predicate(PREDICATE_SYMBOL, variablesSetOne);
            // So we have unique references
            Predicate predicateWithoutReplacementVariableOne = new Predicate(PREDICATE_SYMBOL, variablesSetTwo);
            Predicate predicateWithoutReplacementVariableTwo = new Predicate(PREDICATE_SYMBOL, variablesSetTwo);

            BinaryConnective root     = new Conjunction();
            BinaryConnective rootLeft = new BiImplication();

            rootLeft.LeftSuccessor  = predicateWithoutReplacementVariableOne;
            rootLeft.RightSuccessor = predicateWithReplacementVariable;

            root.LeftSuccessor  = rootLeft;
            root.RightSuccessor = predicateWithoutReplacementVariableTwo;


            char replacementVariable = 'c';

            // Act
            root.Replace(variableToBeReplaced, replacementVariable);

            bool isReplacedOnPredicateWithVariable       = predicateWithReplacementVariable.IsReplaced(variableToBeReplaced);
            bool isReplacedOnPredicateWithoutVariableOne = predicateWithoutReplacementVariableOne.IsReplaced(variableToBeReplaced);
            bool isReplacedOnPredicateWithoutVariableTwo = predicateWithoutReplacementVariableTwo.IsReplaced(variableToBeReplaced);

            // Assert
            isReplacedOnPredicateWithVariable.Should().BeTrue($"Since the bound variable {variableToBeReplaced} should be repalced replaced by {replacementVariable}");
            isReplacedOnPredicateWithoutVariableOne.Should().BeFalse($"Since the predicate does NOT contain {variableToBeReplaced}");
            isReplacedOnPredicateWithoutVariableTwo.Should().BeFalse($"Since the predicate does NOT contain {variableToBeReplaced}");
        }