Exemplo n.º 1
0
        // By dumb luck this could fail if it generated two identical successors for the disjunction!
        public void Constructor_CreateAlphaRuleFromNegationOfDisjunctionOfLiterals_SetOfLengthTwoReturnedWithTwoNegatedLiterals()
        {
            // Arrange
            Disjunction disjunction = (Disjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Disjunction.SYMBOL);

            Negation negatedDisjunction = new Negation();

            negatedDisjunction.LeftSuccessor = disjunction;

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

            SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositions);
            SemanticTableauxElement child            = alphaRuleElement.LeftChild;

            // Act
            HashSet <Proposition> childPropositions = child.Propositions;

            int actualNumberOfLiterals   = childPropositions.Count;
            int expectedNumberOfLiterals = 2;

            // Assert
            actualNumberOfLiterals.Should().Be(expectedNumberOfLiterals, "Because a disjunction of two literals was given");

            foreach (Proposition p in childPropositions)
            {
                p.Should().BeOfType <Negation>("Because for this alpha rule, the negation of both literals is returned");
            }
        }
Exemplo n.º 2
0
        public void Constructor_CreateUniversalQuantifierNoReplacementVariablesPresent_GammaRuleShouldNotBeAppliedNoChildrenGenerated()
        {
            // Arrange
            char boundVariable = PropositionGenerator.GenerateBoundVariable();

            List <char> boundVariables = new List <char>()
            {
                boundVariable
            };
            Predicate predicate = new Predicate(PropositionGenerator.GetRandomVariableLetter(), boundVariables);

            UniversalQuantifier universalQuantifier = new UniversalQuantifier(boundVariable);

            universalQuantifier.LeftSuccessor = predicate;

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

            // Act
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);
            bool isReplaced = predicate.IsReplaced(boundVariable);

            // Assert
            isReplaced.Should().BeFalse("Because no replacement variables are available");
            semanticTableauxElement.LeftChild.Should().BeNull("Because no replacement variables are available and thus no child was created");
        }
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 NodeLabel_CreateNodeLabelWithBothChildrenAndNotClosed_ExpectedLabelWithChildrenIncluded()
        {
            // Arrange
            Disjunction disjunction = new Disjunction();

            disjunction.LeftSuccessor  = new Proposition('B');
            disjunction.RightSuccessor = new Proposition('R');

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

            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);

            semanticTableauxElement.NodeNumber            = 1;
            semanticTableauxElement.LeftChild.NodeNumber  = 2;
            semanticTableauxElement.RightChild.NodeNumber = 3;

            // Act
            string actualNodeLabel = semanticTableauxElement.NodeLabel();

            string expectedNodeLabel = $"node{semanticTableauxElement.NodeNumber}[ label = \"(B | R)\" ]\n";

            expectedNodeLabel += $"node1 -- node2\n";
            expectedNodeLabel += $"node{semanticTableauxElement.NodeNumber + 1}[ label = \"B\" ]\n";
            expectedNodeLabel += $"node1 -- node3\n";
            expectedNodeLabel += $"node{semanticTableauxElement.NodeNumber + 2}[ label = \"R\" ]\n";

            // Assert
            actualNodeLabel.Should().Be(expectedNodeLabel, "Because that's the format required for graphviz plus our own choice of display");
        }
Exemplo n.º 5
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.º 6
0
        public void Constructor_CreateAlphaRuleFromNegatedNandOfLiterals_SetOfLengthTwoReturnedWithTwoLiterals()
        {
            // Arrange
            Nand     nand        = (Nand)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Nand.SYMBOL);
            Negation negatedNand = new Negation();

            negatedNand.LeftSuccessor = nand;

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

            SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositions);
            SemanticTableauxElement child            = alphaRuleElement.LeftChild;

            // Act
            HashSet <Proposition> childPropositions = child.Propositions;

            int actualNumberOfLiterals   = childPropositions.Count;
            int expectedNumberOfLiterals = 2;

            // Assert
            actualNumberOfLiterals.Should().Be(expectedNumberOfLiterals, "Because a conjunction of two literals was given");
        }
Exemplo n.º 7
0
        public void IsClosed_ContradictionByConjunction_AfterCreatingChildElementContainsContradictionClosedShouldReturnTrue()
        {
            // Arrange
            Conjunction contradiction = new Conjunction();

            Proposition child = new Proposition('Z');

            contradiction.LeftSuccessor = child;

            Negation negatedChild = new Negation();

            negatedChild.LeftSuccessor   = child;
            contradiction.RightSuccessor = negatedChild;

            Proposition p = new Proposition('G');

            HashSet <Proposition> propositionSet = new HashSet <Proposition>()
            {
                contradiction,
                p
            };

            // Act
            SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositionSet);
            bool alphaRuleClosedByChild = alphaRuleElement.IsClosed();

            // Assert
            alphaRuleClosedByChild.Should().BeTrue("Because the child alpha rule element should close the branch by contradiction.");
        }
Exemplo n.º 8
0
        public void Constructor_CreateNegatedBiImplicationOfLiterals_BetaRuleShouldBeAppliedBothChildrenShouldHaveSetsOfTwoElementsOneLiteralAndOneNegatedLiteralInEachSet()
        {
            // Arrange
            Negation      negatedBiImplication = new Negation();
            BiImplication biImplication        = (BiImplication)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(BiImplication.SYMBOL);

            negatedBiImplication.LeftSuccessor = biImplication;

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

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

            int actualNumberOfPropositionsInLeftSet  = propositionSetOfLeftChild.Count;
            int actualNumberOfPropositionsInRightSet = propositionSetOfRightChild.Count;
            int expectedNumberOfPropositionsInSet    = 2;

            // Assert
            string message = "Because both the left and right set should have two children in their set after applying beta rule for negated bi-implication.";

            actualNumberOfPropositionsInLeftSet.Should().Be(expectedNumberOfPropositionsInSet, message);
            actualNumberOfPropositionsInRightSet.Should().Be(expectedNumberOfPropositionsInSet, message);

            TestSetToHaveOneLiteralAndOneNegatedLiteral(propositionSetOfLeftChild);
            TestSetToHaveOneLiteralAndOneNegatedLiteral(propositionSetOfRightChild);
        }
Exemplo n.º 9
0
        public void NodeLabel_CreateNodeLabelWithReplacementVariablePResent_ExpectedLabelToIncludeReplacementVariables()
        {
            // Arrange
            Predicate predicate = new Predicate('P', new List <char>()
            {
                'x', 'y'
            });

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

            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);

            semanticTableauxElement.ReplacementVariables = new HashSet <char>()
            {
                'a', 'b'
            };

            semanticTableauxElement.NodeNumber = 1;

            // Act
            string actualNodeLabel = semanticTableauxElement.NodeLabel();

            string expectedNodeLabel = $"node1[ label = \"< a, b >\nP(x, y)\" ]\n";

            // Assert
            actualNodeLabel.Should().Be(expectedNodeLabel, "Because that's the format required for graphviz plus our own choice of display");
        }
Exemplo n.º 10
0
        public void IsClosed_CreateBetaRuleFromDisjunctionWithAdditionalLiteralsContradictingBothBranches_ExpectedParentClosed()
        {
            // Arrange
            Disjunction disjunction = (Disjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Disjunction.SYMBOL);

            Negation negatedLeftLiteral = new Negation();

            negatedLeftLiteral.LeftSuccessor = disjunction.LeftSuccessor;

            Negation negatedRightLiteral = new Negation();

            negatedRightLiteral.LeftSuccessor = disjunction.RightSuccessor;

            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                negatedLeftLiteral,
                disjunction,
                negatedRightLiteral
            };

            // Act
            SemanticTableauxElement betaRuleElement = new SemanticTableauxElement(propositions);
            bool parentClosed = betaRuleElement.IsClosed();

            // Assert
            parentClosed.Should().BeTrue("Because the beta rule contains two contradictions, each of which should close one of the branches");
        }
Exemplo n.º 11
0
        public void IsClosed_TestIsClosedWhenContradictionInSet_ExpectedTrueReturned(bool leftNegated)
        {
            // Arrange
            Disjunction fillerProposition = new Disjunction();
            Proposition child             = new Proposition('Z');

            fillerProposition.LeftSuccessor  = child;
            fillerProposition.RightSuccessor = child;

            Proposition p        = new Proposition('G');
            Negation    pNegated = new Negation();

            pNegated.LeftSuccessor = p;

            HashSet <Proposition> propositionSet = null;

            if (leftNegated)
            {
                propositionSet = new HashSet <Proposition>()
                {
                    pNegated,
                    fillerProposition,
                    fillerProposition,
                    p,
                    fillerProposition
                };
            }
            else
            {
                propositionSet = new HashSet <Proposition>()
                {
                    p,
                    fillerProposition,
                    fillerProposition,
                    pNegated,
                    fillerProposition
                };
            }

            SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositionSet);

            // Act
            bool isBranchClosed = alphaRuleElement.IsClosed();

            // Assert
            isBranchClosed.Should().BeTrue("Because the tableaux element has a contradiction in its set.");
        }
Exemplo n.º 12
0
        public void IsClosed_TestIsClosedWhenChildNullAndNoContradictionInSet_ExpectedFalseReturned()
        {
            // Arrange
            HashSet <Proposition> propositionSet = new HashSet <Proposition>()
            {
                PropositionGenerator.GetRandomProposition(),
                                  PropositionGenerator.GetRandomProposition()
            };

            SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositionSet);

            // Act
            bool isBranchClosed = alphaRuleElement.IsClosed();

            // Assert
            isBranchClosed.Should().BeFalse("Because the tableaux element has no contradiction and no children, thus was not closed.");
        }
Exemplo n.º 13
0
        public void IsClosed_ConstantTrue_ExpectedFalseReturned()
        {
            // Arrange
            Proposition proposition = new True();

            HashSet <Proposition> propositionSet = new HashSet <Proposition>()
            {
                proposition
            };

            SemanticTableauxElement element = new SemanticTableauxElement(propositionSet);

            // Act
            bool isBranchClosed = element.IsClosed();

            // Assert
            isBranchClosed.Should().BeFalse("Because the tableaux element has true in its set, which does not contradict.");
        }
Exemplo n.º 14
0
        public void IsClosed_ContradictionByConstantFalse_ExpectedTrueReturned()
        {
            // Arrange
            Proposition proposition = new False();

            HashSet <Proposition> propositionSet = new HashSet <Proposition>()
            {
                proposition
            };

            SemanticTableauxElement element = new SemanticTableauxElement(propositionSet);

            // Act
            bool isBranchClosed = element.IsClosed();

            // Assert
            isBranchClosed.Should().BeTrue("Because the tableaux element has false in its set which is a contradiction.");
        }
Exemplo n.º 15
0
        public void Constructor_CreateNegatedExistentialQuantifierWithReplacementVariablePresent_GammaRuleShouldBeAppliedAndNewChildrenCreated()
        {
            // Arrange
            char boundVariable = PropositionGenerator.GenerateBoundVariable();

            List <char> boundVariables = new List <char>()
            {
                boundVariable
            };
            Predicate predicate = new Predicate(PropositionGenerator.GetRandomVariableLetter(), boundVariables);

            ExistentialQuantifier existentialQuantifier = new ExistentialQuantifier(boundVariable);

            existentialQuantifier.LeftSuccessor = predicate;

            Negation negatedExistentialQuantifier = new Negation();

            negatedExistentialQuantifier.LeftSuccessor = existentialQuantifier;

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

            // Act
            char availableReplacementVariable = 'd';
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions, new HashSet <char>()
            {
                availableReplacementVariable
            });

            // Assert
            semanticTableauxElement.LeftChild.Should().NotBeNull("Because children should be created now that a replacement variable is present");

            foreach (Proposition proposition in semanticTableauxElement.LeftChild.Propositions)
            {
                if (proposition is Predicate)
                {
                    Predicate pred       = (Predicate)proposition;
                    bool      isReplaced = pred.IsReplaced(boundVariable);
                    isReplaced.Should().BeTrue($"Because the replacement variable {availableReplacementVariable} is available");
                }
            }
        }
Exemplo n.º 16
0
        public void Constructor_CreateNegatedUniversalQuantifier_DeltaRuleShouldBeAppliedChildShouldBePredicateAndVariableShouldBeIntroduced()
        {
            // Arrange
            char boundVariable = PropositionGenerator.GenerateBoundVariable();

            List <char> boundVariables = new List <char>()
            {
                boundVariable
            };
            Predicate predicate = new Predicate(PropositionGenerator.GetRandomVariableLetter(), boundVariables);

            UniversalQuantifier universalQuantifier = new UniversalQuantifier(boundVariable);

            universalQuantifier.LeftSuccessor = predicate;

            Negation negatedUniversalQuantifier = new Negation();

            negatedUniversalQuantifier.LeftSuccessor = universalQuantifier;

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

            // Act
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);
            List <char>             replacementVariables    = semanticTableauxElement.LeftChild.ReplacementVariables.ToList();

            int expectedNumberOfReplacementVariables = 1;
            int actualNumberOfReplacementVariables   = replacementVariables.Count;

            // Assert
            actualNumberOfReplacementVariables.Should().Be(expectedNumberOfReplacementVariables, "Because the only bound variable should be replaced based on the rules");

            foreach (Proposition proposition in semanticTableauxElement.LeftChild.Propositions)
            {
                if (proposition is Predicate)
                {
                    predicate = (Predicate)proposition;
                    bool isReplaced = predicate.IsReplaced(boundVariable);
                    isReplaced.Should().BeTrue("Because after applying a delta rule, the only bound variable in the predicate should be replaced");
                }
            }
        }
Exemplo n.º 17
0
        public void Constructor_BetaRuleGiven_ExpectedLeftAndRightChildToNotBeNullAndASemanticTableauxElement()
        {
            // Arrange
            Disjunction disjunction = (Disjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Disjunction.SYMBOL);

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

            // Act
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);

            // Assert
            string message = "Because on a beta rule both children are created";

            semanticTableauxElement.LeftChild.Should().BeOfType <SemanticTableauxElement>(message);
            semanticTableauxElement.RightChild.Should().BeOfType <SemanticTableauxElement>(message);
        }
Exemplo n.º 18
0
        public void Constructor_AlphaRuleGiven_ExpectedLeftChildToNotBeNullAndASemanticTableauxElement()
        {
            // Arrange
            Conjunction conjunction = (Conjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Conjunction.SYMBOL);

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

            // Act
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);

            // Assert
            string message = "Because on an alpha rule only one child is created";

            semanticTableauxElement.LeftChild.Should().BeOfType <SemanticTableauxElement>(message);
            semanticTableauxElement.RightChild.Should().BeNull(message);
        }
Exemplo n.º 19
0
        public void NodeLabel_CreateNodeLabelWithoutChildrenAndNotClosed_ExpectedLabelWithOnlyPropositions()
        {
            // Arrange
            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                new Proposition('P')
            };

            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);

            semanticTableauxElement.NodeNumber = 1;

            // Act
            string actualNodeLabel   = semanticTableauxElement.NodeLabel();
            string expectedNodeLabel = $"node{semanticTableauxElement.NodeNumber}[ label = \"P\" ]\n";

            // Assert
            actualNodeLabel.Should().Be(expectedNodeLabel, "Because that's the format required for graphviz plus our own choice of display");
        }
Exemplo n.º 20
0
        public void IsClosed_ContradictionByNegatedTrue_ExpectedTrueReturned()
        {
            // Arrange
            Negation    negatedTrue = new Negation();
            Proposition proposition = new True();

            negatedTrue.LeftSuccessor = proposition;

            HashSet <Proposition> propositionSet = new HashSet <Proposition>()
            {
                negatedTrue
            };

            SemanticTableauxElement element = new SemanticTableauxElement(propositionSet);

            // Act
            bool isBranchClosed = element.IsClosed();

            // Assert
            isBranchClosed.Should().BeTrue("Because the tableaux element has a negated true in its set, which DOES contradict as it is equivalent to False.");
        }
Exemplo n.º 21
0
        public void IsClosed_NegatedFalse_ExpectedFalseReturned()
        {
            // Arrange
            Negation    negatedFalse = new Negation();
            Proposition proposition  = new False();

            negatedFalse.LeftSuccessor = proposition;

            HashSet <Proposition> propositionSet = new HashSet <Proposition>()
            {
                negatedFalse
            };

            SemanticTableauxElement element = new SemanticTableauxElement(propositionSet);

            // Act
            bool isBranchClosed = element.IsClosed();

            // Assert
            isBranchClosed.Should().BeFalse("Because the tableaux element has a negated false (aka true) in its set.");
        }
Exemplo n.º 22
0
        public void IsClosed_NoContradictionInSetWithConjunctionAsAlphaRuleChild_AfterCreatingChildContainsIsClosedShouldReturnFalse()
        {
            // Arrange
            Conjunction conjunction = new Conjunction();
            Proposition child       = new Proposition('Z');

            conjunction.LeftSuccessor  = child;
            conjunction.RightSuccessor = child;

            HashSet <Proposition> propositionSet = new HashSet <Proposition>()
            {
                conjunction
            };

            // Act
            SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositionSet);
            bool alphaRuleClosedByChild = alphaRuleElement.IsClosed();

            // Assert
            alphaRuleClosedByChild.Should().BeFalse("Because the child alpha rule element does not contain a contradiction.");
        }
Exemplo n.º 23
0
        public void Constructor_CreateAlphaRuleFromConjunctionOfLiteralsWhenBetaRuleInPropositionSetAsWell_ChildrenShouldBeCreatedBasedOnAlphaRule()
        {
            // Arrange
            Conjunction conjunction = (Conjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Conjunction.SYMBOL);
            Disjunction disjunction = (Disjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Disjunction.SYMBOL);

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

            // Act
            SemanticTableauxElement betaRuleElement = new SemanticTableauxElement(propositions);
            SemanticTableauxElement leftChild       = betaRuleElement.LeftChild;
            SemanticTableauxElement rightChild      = betaRuleElement.RightChild;

            // Assert
            leftChild.Should().BeOfType <SemanticTableauxElement>("Because the alpha rule should be applied");
            rightChild.Should().BeNull("Because when applying the alpha rule the right child would not be assigned");
        }
Exemplo n.º 24
0
        public void Constructor_CreateBetaRuleFromImplicationOfLiterals_SetOfLengthOneForEachChildWithOneNegatedLiteral()
        {
            // Arrange
            Implication implication = (Implication)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Implication.SYMBOL);

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

            SemanticTableauxElement betaRuleElement = new SemanticTableauxElement(propositions);
            SemanticTableauxElement leftChild       = betaRuleElement.LeftChild;
            SemanticTableauxElement rightChild      = betaRuleElement.RightChild;

            // Act
            HashSet <Proposition> leftChildPropositions  = leftChild.Propositions;
            HashSet <Proposition> rightChildPropositions = rightChild.Propositions;

            int actualNumberOfLiteralsInLeftChild  = leftChildPropositions.Count;
            int actualNumberOfLiteralsInRightChild = rightChildPropositions.Count;

            int expectedNumberOfLiterals = 1;

            // Assert
            string message = "Because both proposition literals have been separated into two different sets";

            actualNumberOfLiteralsInLeftChild.Should().Be(expectedNumberOfLiterals, message);
            actualNumberOfLiteralsInRightChild.Should().Be(expectedNumberOfLiterals, message);

            message = "Because based on the rule, the left child should be negated only.";
            foreach (Proposition proposition in leftChildPropositions)
            {
                proposition.Should().BeOfType <Negation>(message);
            }

            foreach (Proposition proposition in rightChildPropositions)
            {
                proposition.Should().Be(implication.RightSuccessor, message);
            }
        }
Exemplo n.º 25
0
        public void NodeLabel_CreateNodeLabelWithConstantContradictionToClose_ExpectedLabelWithColorRed()
        {
            // Arrange
            False contradiction = new False();

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

            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);

            semanticTableauxElement.NodeNumber = 1;

            // Act
            string actualNodeLabel = semanticTableauxElement.NodeLabel();

            string expectedNodeLabel = $"node{semanticTableauxElement.NodeNumber}[ label = \"0\", color = red ]\n";

            // Assert
            actualNodeLabel.Should().Be(expectedNodeLabel, "Because that's the format required for graphviz plus our own choice of display");
        }
Exemplo n.º 26
0
        public void IsClosed_CreateNegatedBiImplicationOfLiteralsWithLiteralsInParentSetToCloseBranches_ParentElementShouldBeClosed()
        {
            // Arrange
            BiImplication biImplication  = (BiImplication)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(BiImplication.SYMBOL);
            Proposition   literal        = biImplication.LeftSuccessor;
            Negation      negatedLiteral = new Negation();

            negatedLiteral.LeftSuccessor = biImplication.LeftSuccessor;

            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                literal,
                biImplication,
                negatedLiteral
            };

            // Act
            SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions);

            // Assert
            semanticTableauxElement.IsClosed().Should().BeTrue("Because it should be possible to close branches when there is at least any of the literals in the parent set as well as any negated literal");
        }
Exemplo n.º 27
0
        public void Constructor_CreateAlphaRuleFromNegationOfImplicationOfLiterals_SetOfLengthTwoReturnedWithRightSuccessorNegated()
        {
            // Arrange
            Implication implication = (Implication)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Implication.SYMBOL);

            Negation negatedImplication = new Negation();

            negatedImplication.LeftSuccessor = implication;

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

            SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositions);
            SemanticTableauxElement child            = alphaRuleElement.LeftChild;

            // Act
            HashSet <Proposition> childPropositions = child.Propositions;

            int actualNumberOfLiterals   = childPropositions.Count;
            int expectedNumberOfLiterals = 2;

            // Assert
            actualNumberOfLiterals.Should().Be(expectedNumberOfLiterals, "Because an implication of two literals was given");

            foreach (Proposition proposition in childPropositions)
            {
                if (proposition.GetType() == typeof(Negation))
                {
                    Negation negatedLiteral = (Negation)proposition;
                    negatedLiteral.LeftSuccessor.CompareTo(implication.RightSuccessor).Should().Be(0, "Because it is right negated successor of the implication.");
                }
                else
                {
                    proposition.CompareTo(implication.LeftSuccessor).Should().Be(0, "Because it is the left not negated successor of the implication.");
                }
            }
        }
Exemplo n.º 28
0
        private void TestConstructorForNotAndEquivalent(UnaryConnective connective)
        {
            // Arrange
            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                connective
            };

            SemanticTableauxElement betaRuleElement = new SemanticTableauxElement(propositions);
            SemanticTableauxElement leftChild       = betaRuleElement.LeftChild;
            SemanticTableauxElement rightChild      = betaRuleElement.RightChild;

            // Act
            HashSet <Proposition> leftChildPropositions  = leftChild.Propositions;
            HashSet <Proposition> rightChildPropositions = rightChild.Propositions;

            int actualNumberOfLiteralsInLeftChild  = leftChildPropositions.Count;
            int actualNumberOfLiteralsInRightChild = rightChildPropositions.Count;

            int expectedNumberOfLiterals = 1;

            // Assert
            string message = "Because both proposition literals have been separated into two different sets";

            actualNumberOfLiteralsInLeftChild.Should().Be(expectedNumberOfLiterals, message);
            actualNumberOfLiteralsInRightChild.Should().Be(expectedNumberOfLiterals, message);

            message = "Because based on the rule, both children should be negated.";
            foreach (Proposition proposition in leftChildPropositions)
            {
                proposition.Should().BeOfType <Negation>(message);
            }

            foreach (Proposition proposition in rightChildPropositions)
            {
                proposition.Should().BeOfType <Negation>(message);
            }
        }
Exemplo n.º 29
0
        public void IsClosed_CreateBetaRuleFromDisjunctionWithAdditionalLiteralContradictingRightBranch_ExpectedRightBranchClosedButNotTheParent()
        {
            // Arrange
            Disjunction disjunction = (Disjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Disjunction.SYMBOL);

            Negation negatedRightLiteral = new Negation();

            negatedRightLiteral.LeftSuccessor = disjunction.RightSuccessor;

            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                disjunction,
                negatedRightLiteral
            };

            // Act
            SemanticTableauxElement betaRuleElement = new SemanticTableauxElement(propositions);
            bool parentClosed = betaRuleElement.IsClosed();
            bool rightClosed  = betaRuleElement.RightChild.IsClosed();

            // Assert
            parentClosed.Should().BeFalse("Because only the right branch is closed off by a contradiction.");
            rightClosed.Should().BeTrue("Because the beta rule contains a contradiction for the right branch");
        }