Ejemplo n.º 1
0
        private bool IsInDnf(Proposition dnfRoot)
        {
            bool dnf = true;

            Stack <Proposition> propositionStack = new Stack <Proposition>();

            propositionStack.Push(dnfRoot);

            Proposition currentProposition = dnfRoot;

            while (propositionStack.Count > 0)
            {
                if (currentProposition.GetType() == typeof(Conjunction))
                {
                    Conjunction conjunction = (Conjunction)currentProposition;
                    dnf = checkIfNotFollowedByDisjunction(conjunction);

                    if (!dnf) // If it fails anywhere in the syntax tree we can early exit.
                    {
                        return(dnf);
                    }
                }
                else
                {
                    AddChildrenToStack(ref propositionStack, currentProposition);
                }

                currentProposition = propositionStack.Pop();
            }

            return(dnf);
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        public void GenerateRandomConstant_IntegerForConstantGiven_ExpectedTrueOrFalseReturned(int coinFlip, Type type)
        {
            // Arrange // Act
            Proposition generatedProposition = PropositionGenerator.GenerateRandomConstant(coinFlip);

            // Assert
            generatedProposition.GetType().Should().Be(type, "Because based on that integer either True or False is returned.");
        }
Ejemplo n.º 4
0
        public void GeneratePropositionByRandomChoice_PositiveIntegerGiven_ExpectedCorrespondingObjectReturned(int choice, Type type)
        {
            // Arrange
            PropositionGenerator propositionGenerator = new PropositionGenerator();

            // Act
            Proposition generatedProposition = propositionGenerator.GeneratePropositionByRandomChoice(choice);

            // Assert
            generatedProposition.GetType().Should().Be(type, "Because based on that generated integer a specific proposition should be returned");
        }
Ejemplo n.º 5
0
        public void Parse_DifferentValidPrefixPropositions_SuccessfullyParsedPropositionRootReturned(string proposition, Type typeOfRoot)
        {
            // Arrange
            parser = new Parser(proposition);

            // Act
            Proposition root = parser.Parse();

            // Assert
            Assert.Equal(root.GetType(), typeOfRoot);
        }
Ejemplo n.º 6
0
        private bool checkIfNotFollowedByDisjunction(Conjunction conjunction)
        {
            Stack <Proposition> propositionStack = new Stack <Proposition>();

            propositionStack.Push(conjunction);
            Proposition currentProposition = conjunction;

            while (propositionStack.Count > 0)
            {
                if (currentProposition.GetType() == typeof(Disjunction))
                {
                    return(false);
                }

                AddChildrenToStack(ref propositionStack, currentProposition);
                currentProposition = propositionStack.Pop();
            }

            return(true);
        }