public void Constructor_CreateNegatedBiImplicationOfLiterals_BetaRuleShouldBeAppliedBothChildrenShouldHaveSetsOfTwoElementsOneLiteralAndOneNegatedLiteralInEachSet() { // Arrange Negation negatedBiImplication = new Negation(); BiImplication biImplication = (BiImplication)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(BiImplication.SYMBOL); negatedBiImplication.LeftSuccessor = biImplication; HashSet <Proposition> propositions = new HashSet <Proposition>() { negatedBiImplication }; // Act SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions); HashSet <Proposition> propositionSetOfLeftChild = semanticTableauxElement.LeftChild.Propositions; HashSet <Proposition> propositionSetOfRightChild = semanticTableauxElement.RightChild.Propositions; int actualNumberOfPropositionsInLeftSet = propositionSetOfLeftChild.Count; int actualNumberOfPropositionsInRightSet = propositionSetOfRightChild.Count; int expectedNumberOfPropositionsInSet = 2; // Assert string message = "Because both the left and right set should have two children in their set after applying beta rule for negated bi-implication."; actualNumberOfPropositionsInLeftSet.Should().Be(expectedNumberOfPropositionsInSet, message); actualNumberOfPropositionsInRightSet.Should().Be(expectedNumberOfPropositionsInSet, message); TestSetToHaveOneLiteralAndOneNegatedLiteral(propositionSetOfLeftChild); TestSetToHaveOneLiteralAndOneNegatedLiteral(propositionSetOfRightChild); }
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"); }
public void Constructor_CreateDoubleNegationOfLiteral_LeftChildCreatedWithNegationRemoved() { // Arrange Negation negation = (Negation)PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL); Negation doubleNegation = new Negation(); doubleNegation.LeftSuccessor = negation; HashSet <Proposition> propositions = new HashSet <Proposition>() { doubleNegation }; // Act SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions); HashSet <Proposition> propositionSetOfChild = semanticTableauxElement.LeftChild.Propositions; int actualNumberOfPropositionsInSet = propositionSetOfChild.Count; int expectedNumberOfPropositionsInSet = 1; Proposition expectedPropositionInSet = negation.LeftSuccessor; // Assert actualNumberOfPropositionsInSet.Should().Be(expectedNumberOfPropositionsInSet, "Because after removing the negation of one proposition we are left with one proposition"); foreach (Proposition p in propositionSetOfChild) { p.Should().Be(expectedPropositionInSet, "Because the inner most child will be left over after removing it's encapsulating negations"); } }
public void Constructor_CreateDoubleNegationOfLiteralWithAlphaRuleInSet_DoubleNegationShouldHavePrecedence() { // Arrange Negation negation = (Negation)PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL); Negation doubleNegation = new Negation(); doubleNegation.LeftSuccessor = negation; Conjunction conjunction = (Conjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Conjunction.SYMBOL); HashSet <Proposition> propositions = new HashSet <Proposition>() { conjunction, doubleNegation }; // Act SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions); HashSet <Proposition> propositionSetOfChild = semanticTableauxElement.LeftChild.Propositions; int actualNumberOfPropositionsInSet = propositionSetOfChild.Count; int expectedNumberOfPropositionsInSet = 2; // Assert semanticTableauxElement.RightChild.Should().BeNull("Because the double negation is applied first, and thus only the left child is assigned"); actualNumberOfPropositionsInSet.Should().Be(expectedNumberOfPropositionsInSet, "Because double negation would be removed first, and thus the number of propositions in the set of the first child should be " + expectedNumberOfPropositionsInSet); }
public void Constructor_CreateBetaRuleFromNandOfLiterals_SetOfLengthOneForEachChildWithNegatedLiterals() { // Arrange Nand nand = (Nand)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Nand.SYMBOL); TestConstructorForNotAndEquivalent(nand); }
public void IsClosed_CreateBetaRuleFromDisjunctionWithAdditionalLiteralsContradictingBothBranches_ExpectedParentClosed() { // Arrange Disjunction disjunction = (Disjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Disjunction.SYMBOL); Negation negatedLeftLiteral = new Negation(); negatedLeftLiteral.LeftSuccessor = disjunction.LeftSuccessor; Negation negatedRightLiteral = new Negation(); negatedRightLiteral.LeftSuccessor = disjunction.RightSuccessor; HashSet <Proposition> propositions = new HashSet <Proposition>() { negatedLeftLiteral, disjunction, negatedRightLiteral }; // Act SemanticTableauxElement betaRuleElement = new SemanticTableauxElement(propositions); bool parentClosed = betaRuleElement.IsClosed(); // Assert parentClosed.Should().BeTrue("Because the beta rule contains two contradictions, each of which should close one of the branches"); }
public void IsReplaced_ReplacingExistingBoundVariableInBinaryConnectiveComposedOfPredicates_BothChildrenShouldReturnTrue(char connectiveSymbol) { // Arrange char existingVariable = 'y'; List <char> variables = new List <char>() { existingVariable }; Predicate leftPredicate = new Predicate(PREDICATE_SYMBOL, variables); Predicate rightPredicate = new Predicate('Q', variables); BinaryConnective binaryConnective = PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(connectiveSymbol); binaryConnective.LeftSuccessor = leftPredicate; binaryConnective.RightSuccessor = rightPredicate; char replacementVariable = 'c'; // Act binaryConnective.Replace(existingVariable, replacementVariable); bool leftIsReplaced = leftPredicate.IsReplaced(existingVariable); bool rightIsReplaced = rightPredicate.IsReplaced(existingVariable); // Assert leftIsReplaced.Should().BeTrue($"Since the bound variable {existingVariable} should be repalced replaced by {replacementVariable}"); rightIsReplaced.Should().BeTrue($"Since the bound variable {existingVariable} should be repalced replaced by {replacementVariable}"); }
// By dumb luck this could fail if it generated two identical successors for the disjunction! public void Constructor_CreateAlphaRuleFromNegationOfDisjunctionOfLiterals_SetOfLengthTwoReturnedWithTwoNegatedLiterals() { // Arrange Disjunction disjunction = (Disjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Disjunction.SYMBOL); Negation negatedDisjunction = new Negation(); negatedDisjunction.LeftSuccessor = disjunction; HashSet <Proposition> propositions = new HashSet <Proposition>() { negatedDisjunction }; SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositions); SemanticTableauxElement child = alphaRuleElement.LeftChild; // Act HashSet <Proposition> childPropositions = child.Propositions; int actualNumberOfLiterals = childPropositions.Count; int expectedNumberOfLiterals = 2; // Assert actualNumberOfLiterals.Should().Be(expectedNumberOfLiterals, "Because a disjunction of two literals was given"); foreach (Proposition p in childPropositions) { p.Should().BeOfType <Negation>("Because for this alpha rule, the negation of both literals is returned"); } }
public void Constructor_CreateAlphaRuleFromNegatedNandOfLiterals_SetOfLengthTwoReturnedWithTwoLiterals() { // Arrange Nand nand = (Nand)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Nand.SYMBOL); Negation negatedNand = new Negation(); negatedNand.LeftSuccessor = nand; HashSet <Proposition> propositions = new HashSet <Proposition>() { negatedNand }; SemanticTableauxElement alphaRuleElement = new SemanticTableauxElement(propositions); SemanticTableauxElement child = alphaRuleElement.LeftChild; // Act HashSet <Proposition> childPropositions = child.Propositions; int actualNumberOfLiterals = childPropositions.Count; int expectedNumberOfLiterals = 2; // Assert actualNumberOfLiterals.Should().Be(expectedNumberOfLiterals, "Because a conjunction of two literals was given"); }
public void IsReplaced_ReplacingExistingBoundVariableInUnaryConnectiveComposedOfAPredicate_ChildShouldReturnTrue(char connectiveSymbol) { // Arrange char existingVariable = 'w'; List <char> variables = new List <char>() { existingVariable }; Predicate predicate = new Predicate(PREDICATE_SYMBOL, variables); UnaryConnective unaryConnective = PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(connectiveSymbol); unaryConnective.LeftSuccessor = predicate; char replacementVariable = 'c'; // Act unaryConnective.Replace(existingVariable, replacementVariable); bool leftIsReplaced = predicate.IsReplaced(existingVariable); // Assert leftIsReplaced.Should().BeTrue($"Since the bound variable {existingVariable} should be repalced replaced by {replacementVariable}"); }
public void CreateContradictionFromProposition_NullGiven_ExpectedNullReferenceExceptionThrown() { // Arrange // Act Action act = () => PropositionGenerator.CreateContradictionFromProposition(null); // Assert act.Should().Throw <NullReferenceException>("Because create contradiction requires a proposition"); }
public void GetRandomPropositionSymbol_CallToGetRandomPropositionSymbol_ExpectedRandomPropositionReturned() { // Arrange // Act Proposition randomProposition = PropositionGenerator.GetRandomPropositionSymbol(); // Assert randomProposition.Should().BeOfType <Proposition>("Because a proposition with a random variable letter is generated"); }
public void CreateBinaryConnectiveWithRandomSymbols_NonExistingCreateBinaryConnectiveWithRandomSymbols_ExpectedArgumentNullExceptionThrown(char invalidConnectiveSymbol) { // Arrange // Act Action act = () => PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(invalidConnectiveSymbol); // Assert act.Should().Throw <ArgumentNullException>("Because an invalid binary connective symbol is given."); }
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"); }
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."); }
public void GetBoundVariables_UnaryConnectiveWithPropositionAsSuccessor_ExpectedNotImplementedExceptionThrown() { // Arrange UnaryConnective negation = PropositionGenerator.CreateUnaryConnectiveWithRandomSymbol(Negation.SYMBOL); Action act = () => negation.GetBoundVariables(); // Act // Assert act.Should().Throw <NotImplementedException>("Because an abstract proposition does not have bound variables related to it."); }
public void GetRandomConnectiveSymbol_GetRandomConnectiveSymbol_ExpectedRandomConnectiveSymbolReturned() { // Arrange // Act char randomConnectiveSymbol = PropositionGenerator.GetRandomConnectiveSymbol(); int indexOfConnective = Parser.CONNECTIVES.IndexOf(randomConnectiveSymbol); // Assert indexOfConnective.Should().BeGreaterOrEqualTo(0, "Because a random connective symbol is generated"); }
public void Constructor_CreateBetaRuleFromNegationOfConjunctionOfLiterals_SetOfLengthOneForEachChildWithNegatedLiterals() { // Arrange Conjunction conjunction = (Conjunction)PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(Conjunction.SYMBOL); Negation negatedConjunction = new Negation(); negatedConjunction.LeftSuccessor = conjunction; // Act // Assert TestConstructorForNotAndEquivalent(negatedConjunction); }
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"); }
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); }
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"); }
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 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"); }
public void GeneratePropositionByRandomChoice_IntegerForConstantGiven_ExpectedConstantReturned() { // Arrange PropositionGenerator propositionGenerator = new PropositionGenerator(); // Act int constantChoice = 6; Proposition generatedProposition = propositionGenerator.GeneratePropositionByRandomChoice(constantChoice); // Assert (generatedProposition is Constant).Should().BeTrue("Because based on that integer one of the constants should be returned."); }
public virtual void TestNandify() { // Arrange Proposition validProposition = PropositionGenerator.CreateBinaryConnectiveWithRandomSymbols(symbol); // Act Proposition nandifiedProposition = validProposition.Nandify(); // Assert NandChecker.hasNandStructure(new List <Proposition>() { nandifiedProposition }); }
public void Nandify_CallToNandifyOnValidRandomVariable_ExpectedNandifiedPropositionReturned() { // Arrange Proposition validProposition = PropositionGenerator.GetRandomPropositionSymbol(); // Act Proposition nandifiedProposition = validProposition.Nandify(); // Assert NandChecker.hasNandStructure(new List <Proposition>() { nandifiedProposition }); }
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"); }
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"); }
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 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."); }