public void GetDegree_NullNode_ArgumentNullExceptionThrown() { // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetDegree' throws an 'ArgumentNullException' when the node is null. Assert.Throws <ArgumentNullException>("node", () => walker.GetDegree(null)); }
public void GetDegree_NullWalker_ArgumentNullExceptionThrown() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a null ITreeWalker. NodeWalker <int> walker = null; // Assert that 'GetDegree' throws an 'ArgumentNullException' when the tree walker // is null. Assert.Throws <ArgumentNullException>("walker", () => walker.GetDegree(tree)); }
public void GetDegree() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Get a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // For each node in the tree assert the 'GetDegree' returns the number of children // that the node has. foreach (Node <int> node in walker.PreOrderTraversal(tree)) { Assert.Equal(node.Children.Count, walker.GetDegree(node)); } }
public void GetDescendants_ByKey_ComparerIsInvoked() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Create a mock IComparer. Mock <IEqualityComparer <Node <int> > > mockComparer = new Mock <IEqualityComparer <Node <int> > >(); mockComparer .Setup(mock => mock.Equals(It.IsAny <Node <int> >(), It.IsAny <Node <int> >())) .Returns(true); // Create a key to use for comparison. Any key is fine. Node <int> key = new Node <int>(0); // Execute GetDescendants. walker.GetDescendants(tree, key, mockComparer.Object).ToArray(); // It should be called the same number of times as children of the node being evaluated. mockComparer.Verify(x => x.Equals(It.IsAny <Node <int> >(), It.IsAny <Node <int> >()), Times.Exactly(walker.GetDegree(tree))); }