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}"); }
public virtual void GetBoundVariables_CalledOnABinaryConnective_ExpectedNotImplementedExceptionThrown() { // Arrange BinaryConnective binaryConnective = createBinaryConnective(); Action act = () => binaryConnective.GetBoundVariables(); // Act // Assert act.Should().Throw <NotImplementedException>("Because it is not clear what should happen when calling this on a binary connective"); }
public BinaryPredicate(BinaryConnective connective, Predicate first, Predicate second) { Debug.Assert(connective != null); Debug.Assert(first != null); Debug.Assert(second != null); this.connective = connective; this.first = first; this.second = second; }
private void AddChildrenToStack(ref Stack <Proposition> propositionStack, Proposition proposition) { if (proposition is UnaryConnective) { UnaryConnective unaryConnective = (UnaryConnective)proposition; propositionStack.Push(unaryConnective.LeftSuccessor); } if (proposition is BinaryConnective) { BinaryConnective binaryConnective = (BinaryConnective)proposition; propositionStack.Push(binaryConnective.RightSuccessor); } }
private static void addChildren(BinaryConnective binaryConnective, List <Proposition> queue) { Proposition leftSuccessor = binaryConnective.LeftSuccessor; Proposition rightSuccessor = binaryConnective.RightSuccessor; if (leftSuccessor != null) { queue.Add(leftSuccessor); } if (rightSuccessor != null) { queue.Add(rightSuccessor); } }
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"); }
protected void Copy_CopyingBinaryConnectiveWithTwoRandomVariableSymbols_ExpectedDifferentReferencesForConnective(BinaryConnective originalConenctive) { // Act Proposition copy = originalConenctive.Copy(); bool sameReference = originalConenctive == copy; // Assert originalConenctive.Equals(copy).Should().BeTrue("Because all the data should be equal"); sameReference.Should().BeFalse("Because a copy should be a different object reference"); }
protected void Calculate_DetermineAllPossibleValuesBetweenTwoPropositionVariables(BinaryConnective connective, string message, bool left, bool right, bool expected) { // Arrange connective.LeftSuccessor.TruthValue = left; connective.RightSuccessor.TruthValue = right; // Act bool actualTruthValue = connective.Calculate(); // Assert actualTruthValue.Should().Be(expected, message); }