Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
0
        public void Constructor_ConstructPropositionWithValidCharacterRepresentingVariable_ExpectedObjectToHoldCharacterAsVariable()
        {
            // Arrange
            char randomValidVariableLetter = PropositionGenerator.GetRandomVariableLetter();

            // Act
            Proposition proposition = new Proposition(randomValidVariableLetter);

            // Assert
            proposition.Data.Should().BeEquivalentTo(randomValidVariableLetter, "because the random variable letter should be assigned to the data field by the constructor");
        }
Ejemplo n.º 3
0
        public TruthTableRowTests()
        {
            List <Proposition> propVariables = new List <Proposition>()
            {
                new Proposition(PropositionGenerator.GetRandomVariableLetter())
            };

            proposition = new Mock <Proposition>();
            proposition.Setup(p => p.GetVariables()).Returns(propVariables);
            proposition.Setup(p => p.Calculate()).Returns(false);
        }
Ejemplo n.º 4
0
        public void GetRandomVariableLetter_CallToGetRandomVariableLetter_ExpectedRandomCapitalLetterReturned()
        {
            // Arrange
            string capitalAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            // Act
            char randomVariableLetter  = PropositionGenerator.GetRandomVariableLetter();
            int  indexOfVariableLetter = capitalAlphabet.IndexOf(randomVariableLetter);

            // Assert
            indexOfVariableLetter.Should().BeGreaterOrEqualTo(0, "Because a capital letter from the alphabet should be generated");
        }
Ejemplo n.º 5
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");
                }
            }
        }
Ejemplo n.º 6
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");
                }
            }
        }
Ejemplo n.º 7
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");
        }