Esempio n. 1
0
        public void GetVariablesTest()
        {
            string      input = "=(&(~(b), a),|(=(c,d),>(e,f)))";
            Proposition check = new Proposition(input);

            Assert.AreEqual(6, check.GetVariables().Count());
        }
Esempio n. 2
0
        public void GetVariables_CallToGetVariables_ShouldReturnEmptyListSinceConstantHasNoVariableSymbols()
        {
            // Arrange
            int expectedNumberOfVariables = 0;

            // Act
            List <Proposition> actualVariablesInProposition = constant.GetVariables();

            // Assert
            actualVariablesInProposition.Count.Should().Be(expectedNumberOfVariables, "because a constant has no variable symbols in its expression");
        }
Esempio n. 3
0
        public void Constructor_ConstructWithVariablesAlreadySetOnProposition_ShouldResultInAProperlyConstructedObjectWithANumberOfRowsEqualToNumberOfVariablesToThePowerOfTwo(string toParseExpression, int expectedNumberOfRows)
        {
            // Arrange
            parser = new Parser(toParseExpression);
            Proposition root = parser.Parse();

            // Act
            root.UniqueVariableSet = root.GetVariables();
            TruthTable tt = new TruthTable(root);
            int        actualNumberOfRows = tt.Rows.Count;

            // Assert
            actualNumberOfRows.Should().Be(expectedNumberOfRows);
        }
Esempio n. 4
0
        public void GetVariables_CallGetVariablesOnARandomValidProposition_ExpectedListReturnedWithTheVariableAsIndividualElement()
        {
            // Arrange
            Proposition validProposition = PropositionGenerator.GetRandomPropositionSymbol();

            int expectedNumberOfElements = 1;

            // Act
            List <Proposition> propositionVariables = validProposition.GetVariables();

            // Assert
            propositionVariables.Count.Should().Be(expectedNumberOfElements, "because the proposition variable is an individual variable");
            propositionVariables[0].Should().BeEquivalentTo(validProposition, "because the proposition variable itself is the actual proposition");
        }
Esempio n. 5
0
        public void Parse_UniqueSymbolCharactersInExpression_ShouldResultInUniqueVariables()
        {
            // Arrange
            string proposition = "~(&(|(A, B), C))";
            int    expectedNumberOfVariables = 3;

            parser = new Parser(proposition);

            // Act
            Proposition        root = parser.Parse();
            List <Proposition> expressionVariables = root.GetVariables();

            // Assert
            expressionVariables.Count.Should().Be(expectedNumberOfVariables, "because there should be one proposition variable for each unique character");
        }
Esempio n. 6
0
        public void ToString_MultipleVariablesInTruthTable_NumberOfPiecesShouldBeEquivalentToNumberOfVariablesPlusOneForResultColumn(string toParseExpression)
        {
            // Arrange
            parser = new Parser(toParseExpression);
            Proposition root = parser.Parse();
            TruthTable  tt   = new TruthTable(root);

            int numberOfVariables     = root.GetVariables().Count;
            int numberOfExpectedParts = numberOfVariables + 1;

            // Act
            String result = tt.TableHeader();

            String[] parts = result.Split(TruthTableRow.GetPadding());

            // Assert
            parts.Length.Should().Be(numberOfExpectedParts, "Because the string should display a value for each variable and a result");
        }
Esempio n. 7
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. 8
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. 9
0
        public void Parse_SameSymbolCharacterInExpression_ShouldBeSameObject()
        {
            // Arrange
            char randomSymbol     = PropositionGenerator.GetRandomVariableLetter();
            char randomConnective = PropositionGenerator.GetRandomConnectiveSymbol();

            string proposition = $"{randomConnective}({randomSymbol}, {randomSymbol})";
            int    expectedNumberOfVariables = 1;

            parser = new Parser(proposition);

            // Act
            Proposition        root = parser.Parse();
            List <Proposition> expressionVariables = root.GetVariables();

            // Assert
            expressionVariables.Count.Should().Be(expectedNumberOfVariables, "because there should be one proposition variable for each unique character");
            expressionVariables[0].Data.Should().Be(randomSymbol, "because that is the only given symbol");
        }