Esempio n. 1
0
        public void Simplify_NonSimplifiablTruthTable_ShouldResultInTheOriginalTruthTable(string toParseExpression)
        {
            // Same number of rows
            // These should result in the same sets of rows
            parser = new Parser(toParseExpression);
            Proposition root = parser.Parse();
            TruthTable  tt   = new TruthTable(root);

            // Act
            TruthTable simplifiedTt = tt.Simplify();

            // Assert
            tt.Rows.Count.Should().Be(simplifiedTt.Rows.Count, "Because the expression could not be simplified");
        }
Esempio n. 2
0
        public void Simplify_SimplifiableTruthTable_ShouldResultInSimplifiedTruthTable(string toParseExpression)
        {
            // A simplified truth table has less rows than the original.
            // They are also flagged as simplified and for that reason treated differently
            // Arrange
            parser = new Parser(toParseExpression);
            Proposition root = parser.Parse();
            TruthTable  tt   = new TruthTable(root);

            // Act
            TruthTable simplifiedTt = tt.Simplify();

            // Assert
            tt.Rows.Count.Should().BeGreaterThan(simplifiedTt.Rows.Count, "Because the simplified truth table should have less rows as some could be simplified");
        }
Esempio n. 3
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.");
        }
Esempio n. 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.");
        }
Esempio n. 5
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");
        }
Esempio n. 6
0
        public void GetSimplifiedExpression_ExpressionWithoutDoNotCareVariableGiven_ExpectedEqualNumberOfVariablesInProposition(string nonSimplifiableExpression)
        {
            // Arrange
            parser = new Parser(nonSimplifiableExpression);
            Proposition nonSimplifiableProposition = parser.Parse();

            TruthTable  truthTable           = new TruthTable(nonSimplifiableProposition);
            TruthTable  simplifiedTruthTable = truthTable.Simplify();
            Proposition afterSimplifying     = simplifiedTruthTable.GetSimplifiedExpression();

            // Act
            int numberOfVariablesInOriginal         = nonSimplifiableProposition.GetVariables().Count;
            int actualNumberOfVariablesInSimplified = afterSimplifying.GetVariables().Count;

            int actualNumberOfDontCareVariables = numberOfVariablesInOriginal - actualNumberOfVariablesInSimplified;

            // Assert
            actualNumberOfDontCareVariables.Should().Be(0, $"Because the proposition could NOT be simplified thus should have a difference of 0");
        }
Esempio n. 7
0
        public void GetSimplifiedExpression_ExpressionWithDoNotCareVariableGiven_ExpectedDoNoCareVariableToBeRemovedFromProposition(string simplifiableExpression, int numberOfDoNotCareVariables)
        {
            // Arrange
            parser = new Parser(simplifiableExpression);
            Proposition simplifiableProposition = parser.Parse();

            TruthTable  truthTable           = new TruthTable(simplifiableProposition);
            TruthTable  simplifiedTruthTable = truthTable.Simplify();
            Proposition afterSimplifying     = simplifiedTruthTable.GetSimplifiedExpression();

            // Act
            int numberOfVariablesInOriginal         = simplifiableProposition.GetVariables().Count;
            int actualNumberOfVariablesInSimplified = afterSimplifying.GetVariables().Count;

            int actualNumberOfDontCareVariables = numberOfVariablesInOriginal - actualNumberOfVariablesInSimplified;

            // Assert
            actualNumberOfDontCareVariables.Should().Be(numberOfDoNotCareVariables, $"Because the proposition could be simplified and {numberOfDoNotCareVariables} variables should be removed from the original expression that has {numberOfVariablesInOriginal} variables");
        }
Esempio n. 8
0
        public void Simplify_Should_Produce_Valid_Simplified_TruthTableValues()
        {
            TruthTable table = new TruthTable(VALID_TRUTHTABLE_VALUES);

            table.Simplify().Should().BeEquivalentTo(VALID_SIMPLIFIED_TRUTHTABLE_VALUES);
        }