Beispiel #1
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);
        }
Beispiel #2
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");
            }
        }
Beispiel #3
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");
        }
Beispiel #4
0
        public void Constructor_CreateBetaRuleFromNandOfLiterals_SetOfLengthOneForEachChildWithNegatedLiterals()
        {
            // Arrange
            Nand nand = (Nand)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Nand.SYMBOL);

            TestConstructorForNotAndEquivalent(nand);
        }
Beispiel #5
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");
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void IsReplaced_ReplacingExistingBoundVariableInBinaryConnectiveComposedOfPredicates_BothChildrenShouldReturnTrue(char connectiveSymbol)
        {
            // Arrange
            char existingVariable = 'y';

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

            Predicate leftPredicate  = new Predicate(PREDICATE_SYMBOL, variables);
            Predicate rightPredicate = new Predicate('Q', variables);

            BinaryConnective binaryConnective = PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(connectiveSymbol);

            binaryConnective.LeftSuccessor  = leftPredicate;
            binaryConnective.RightSuccessor = rightPredicate;

            char replacementVariable = 'c';

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

            bool leftIsReplaced  = leftPredicate.IsReplaced(existingVariable);
            bool rightIsReplaced = rightPredicate.IsReplaced(existingVariable);

            // Assert
            leftIsReplaced.Should().BeTrue($"Since the bound variable {existingVariable} should be repalced replaced by {replacementVariable}");
            rightIsReplaced.Should().BeTrue($"Since the bound variable {existingVariable} should be repalced replaced by {replacementVariable}");
        }
        public void CreateBinaryConnectiveWithRandomSymbols_NonExistingCreateBinaryConnectiveWithRandomSymbols_ExpectedArgumentNullExceptionThrown(char invalidConnectiveSymbol)
        {
            // Arrange // Act
            Action act = () => PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(invalidConnectiveSymbol);

            // Assert
            act.Should().Throw <ArgumentNullException>("Because an invalid binary connective symbol is given.");
        }
        public void CreateBinaryConnectiveWithRandomSymbols_ValidBinaryConnectiveSymbolGiven_ExpectedBinaryConnectiveReturned(char connectiveSymbol, Type type)
        {
            // Arrange // Act
            Proposition binaryConnective = PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(connectiveSymbol);

            // Assert
            binaryConnective.GetType().Should().Be(type, "Because that is the type we requested a unary connective from");
        }
Beispiel #10
0
        public void Constructor_CreateBetaRuleFromNegationOfConjunctionOfLiterals_SetOfLengthOneForEachChildWithNegatedLiterals()
        {
            // Arrange
            Conjunction conjunction        = (Conjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Conjunction.SYMBOL);
            Negation    negatedConjunction = new Negation();

            negatedConjunction.LeftSuccessor = conjunction;

            // Act // Assert
            TestConstructorForNotAndEquivalent(negatedConjunction);
        }
Beispiel #11
0
        public virtual void TestNandify()
        {
            // Arrange
            Proposition validProposition = PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(symbol);

            // Act
            Proposition nandifiedProposition = validProposition.Nandify();

            // Assert
            NandChecker.hasNandStructure(new List <Proposition>()
            {
                nandifiedProposition
            });
        }
Beispiel #12
0
        public void CreateDisjunctiveNormalForm_ExpressionGiven_ExpectedPropositionLiteralsAtTheLeavesAndNoDisjunctionDeeperThanConjunction(char expressionSymbol)
        {
            // For the binary connectives, we should check all (both) possible branches if they contain
            // no disjunction below a conjunction

            // Arrange
            BinaryConnective root         = PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(expressionSymbol);
            TruthTable       tt           = new TruthTable(root);
            TruthTable       simplifiedTt = tt.Simplify();

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

            // Assert
            Assert.True(IsInDnf(dnf), "Because this expression should be in DNF");
            Assert.True(IsInDnf(simplifiedDnf), "Because the simplified expression should also be in DNF");
        }
Beispiel #13
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);
        }
Beispiel #14
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);
        }
Beispiel #15
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");
        }
Beispiel #16
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);
            }
        }
Beispiel #17
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.");
                }
            }
        }
Beispiel #18
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");
        }
Beispiel #19
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");
        }
Beispiel #20
0
 protected BinaryConnective createBinaryConnective()
 {
     return(PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(symbol));
 }