Exemplo n.º 1
0
        public void IsReplaced_ReplacingExistingBoundVariableInUnaryConnectiveComposedOfAPredicate_ChildShouldReturnTrue(char connectiveSymbol)
        {
            // Arrange
            char existingVariable = 'w';

            List <char> variables = new List <char>()
            {
                existingVariable
            };

            Predicate predicate = new Predicate(PREDICATE_SYMBOL, variables);

            UnaryConnective unaryConnective = PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(connectiveSymbol);

            unaryConnective.LeftSuccessor = predicate;

            char replacementVariable = 'c';

            // Act
            unaryConnective.Replace(existingVariable, replacementVariable);

            bool leftIsReplaced = predicate.IsReplaced(existingVariable);

            // Assert
            leftIsReplaced.Should().BeTrue($"Since the bound variable {existingVariable} should be repalced replaced by {replacementVariable}");
        }
Exemplo n.º 2
0
        public void Constructor_CreateDoubleNegationOfLiteralWithAlphaRuleInSet_DoubleNegationShouldHavePrecedence()
        {
            // Arrange
            Negation negation       = (Negation)PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL);
            Negation doubleNegation = new Negation();

            doubleNegation.LeftSuccessor = negation;

            Conjunction conjunction = (Conjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Conjunction.SYMBOL);

            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                conjunction,
                doubleNegation
            };

            // Act
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);
            HashSet <Proposition>   propositionSetOfChild   = semanticTableauxElement.LeftChild.Propositions;

            int actualNumberOfPropositionsInSet   = propositionSetOfChild.Count;
            int expectedNumberOfPropositionsInSet = 2;

            // Assert
            semanticTableauxElement.RightChild.Should().BeNull("Because the double negation is applied first, and thus only the left child is assigned");
            actualNumberOfPropositionsInSet.Should().Be(expectedNumberOfPropositionsInSet, "Because double negation would be removed first, and thus the number of propositions in the set of the first child should be " + expectedNumberOfPropositionsInSet);
        }
Exemplo n.º 3
0
        public void Constructor_CreateDoubleNegationOfLiteral_LeftChildCreatedWithNegationRemoved()
        {
            // Arrange
            Negation negation       = (Negation)PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL);
            Negation doubleNegation = new Negation();

            doubleNegation.LeftSuccessor = negation;

            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                doubleNegation
            };

            // Act
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);
            HashSet <Proposition>   propositionSetOfChild   = semanticTableauxElement.LeftChild.Propositions;

            int actualNumberOfPropositionsInSet   = propositionSetOfChild.Count;
            int expectedNumberOfPropositionsInSet = 1;

            Proposition expectedPropositionInSet = negation.LeftSuccessor;

            // Assert
            actualNumberOfPropositionsInSet.Should().Be(expectedNumberOfPropositionsInSet, "Because after removing the negation of one proposition we are left with one proposition");

            foreach (Proposition p in propositionSetOfChild)
            {
                p.Should().Be(expectedPropositionInSet, "Because the inner most child will be left over after removing it's encapsulating negations");
            }
        }
Exemplo n.º 4
0
        public void CreateUnaryConnectiveWithRandomSymbols_ValidUnaryConnectiveSymbolGiven_ExpectedUnaryConnectiveReturned(char connectiveSymbol, Type type)
        {
            // Arrange // Act
            Proposition unaryConnective = PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(connectiveSymbol);

            // Assert
            unaryConnective.GetType().Should().Be(type, "Because that is the type we requested a unary connective from");
        }
Exemplo n.º 5
0
        public void CreateUnaryConnectiveWithRandomSymbols_NonExistingUnaryConnectiveSymbolGiven_ExpectedArgumentNullExceptionThrown(char invalidConnectiveSymbol)
        {
            // Arrange // Act
            Action act = () => PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(invalidConnectiveSymbol);

            // Assert
            act.Should().Throw <ArgumentNullException>("Because an invalid unary connective symbol is given.");
        }
Exemplo n.º 6
0
        public void GetBoundVariables_UnaryConnectiveWithPropositionAsSuccessor_ExpectedNotImplementedExceptionThrown()
        {
            // Arrange
            UnaryConnective negation = PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL);
            Action          act      = () => negation.GetBoundVariables();

            // Act // Assert
            act.Should().Throw <NotImplementedException>("Because an abstract proposition does not have bound variables related to it.");
        }
Exemplo n.º 7
0
        public void CreateDisjunctiveNormalForm_NegatedProposition_ExpectedOriginalNegatedPropositionReturned()
        {
            // Arrange
            Proposition originalProposition = PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL);
            TruthTable  tt           = new TruthTable(originalProposition);
            TruthTable  simplifiedTt = tt.Simplify();

            // Act
            Proposition dnf           = tt.CreateDisjunctiveNormalForm();
            Proposition simplifiedDnf = simplifiedTt.CreateDisjunctiveNormalForm();

            // Assert
            dnf.Should().BeEquivalentTo(originalProposition, "Because the disjunctive normal of a negated proposition literal is the negated literal itself");
            simplifiedDnf.Should().BeEquivalentTo(originalProposition, "Because a negated literal can not be simplified any further and should result in the negated literal itself.");
        }
Exemplo n.º 8
0
        public void GetBoundVariables_UnaryConnectiveWithPredicateAsSuccessor_NonEmptyListOfVariablesReturned()
        {
            // Arrange
            UnaryConnective negation = PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL);

            negation.LeftSuccessor = new Predicate('T', new List <char>()
            {
                'r', 't'
            });

            // Act
            List <char> boundVariables = negation.GetBoundVariables();
            int         expectedNumberOfBoundVariables = 2;
            int         actualNumberOfBoundVariables   = boundVariables.Count;

            // Assert
            actualNumberOfBoundVariables.Should().Be(expectedNumberOfBoundVariables, $"Because a predicate is assigned as successor with {expectedNumberOfBoundVariables} variables assigned");
        }