Example #1
0
        public void Constructor_ParsedPropositionGiven_ShouldResultInNegatedPropositionAsRoot()
        {
            // Arrange
            Proposition      randomValidProposition = PropositionGenerator.GetRandomProposition();
            SemanticTableaux semanticTableaux       = new SemanticTableaux(randomValidProposition);

            // Act
            Proposition root = semanticTableaux.Proposition;

            // Assert
            root.Should().Be(randomValidProposition, "Because the original expression is being evaluated");
        }
        public void CreateContradictionFromProposition_ValidPropositionGiven_ExpectedAllAssignmentsToResultInFalse(bool truthValue)
        {
            // Arrange
            Proposition randomProposition = PropositionGenerator.GetRandomProposition();
            Proposition contradiction     = PropositionGenerator.CreateContradictionFromProposition(randomProposition);

            contradiction.TruthValue = truthValue;

            // Act
            bool actualTruthValue = contradiction.Calculate();

            // Assert
            actualTruthValue.Should().BeFalse("Because a contradiction should always evaluate to false");
        }
        public void CreateTautologyFromProposition_ValidPropositionGiven_ExpectedAllAssignmentsToResultInTrue(bool truthValue)
        {
            // Arrange
            Proposition randomProposition = PropositionGenerator.GetRandomProposition();
            Proposition tautology         = PropositionGenerator.CreateTautologyFromProposition(randomProposition);

            tautology.TruthValue = truthValue;

            // Act
            bool actualTruthValue = tautology.Calculate();

            // Assert
            actualTruthValue.Should().BeTrue("Because a tautology should always evaluate to true");
        }
Example #4
0
        public void CreateDisjunctiveNormalForm_IndividualPropositionGiven_ExpectedIndividualPropositionReturned()
        {
            // Arrange
            Proposition originalProposition = PropositionGenerator.GetRandomProposition();
            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 proposition literal is the literal itself");
            simplifiedDnf.Should().BeEquivalentTo(originalProposition, "Because a literal can not be simplified any further and should result in the literal itself.");
        }
Example #5
0
        public void Copy_CopyQuantifier_ExpectedEqualsToBeTrueButDifferentReferences()
        {
            // Arrange
            Quantifier quantifier = GetQuantifier();

            quantifier.LeftSuccessor = PropositionGenerator.GetRandomProposition();

            // Act
            Proposition copy          = quantifier.Copy();
            bool        equal         = quantifier.Equals(copy);
            bool        sameReference = quantifier == copy;

            // Assert
            equal.Should().BeTrue("Because the quantifier is copied");
            sameReference.Should().BeFalse("Since copies should be different references");
        }
Example #6
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.");
        }
Example #7
0
        private List <Proposition> generateXPropositionVariables(int x)
        {
            Proposition previous       = null;
            Proposition newProposition = null;

            List <Proposition> propositions = new List <Proposition>();

            while (propositions.Count < x)
            {
                previous       = newProposition;
                newProposition = PropositionGenerator.GetRandomProposition();

                if (previous != null && !newProposition.Data.Equals(previous.Data))
                {
                    propositions.Add(newProposition);
                }
            }

            return(propositions);
        }