public void GetDescendants_NullNode_ArgumentNullExceptionThrown() { // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetDescendants' throws an 'ArgumentNullException' when the node is // null. Assert.Throws <ArgumentNullException>( "nodes", () => walker.GetDescendants((IEnumerable <Node <int> >)null, (n, i) => true).ToArray()); Assert.Throws <ArgumentNullException>( "nodes", () => walker.GetDescendants((IEnumerable <Node <int> >)null, (n) => true).ToArray()); Assert.Throws <ArgumentNullException>( "node", () => walker.GetDescendants((Node <int>)null, (n, i) => true).ToArray()); Assert.Throws <ArgumentNullException>( "node", () => walker.GetDescendants((Node <int>)null, (n) => true).ToArray()); }
public void GetDescendants_ByKey_NullNode_ArgumentNullExceptionThrown() { // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetDescendants' throws an 'ArgumentNullException' when the node is // null. Assert.Throws <ArgumentNullException>( "nodes", () => walker.GetDescendants((IEnumerable <Node <int> >)null, default(Node <int>))); Assert.Throws <ArgumentNullException>( "nodes", () => walker.GetDescendants((IEnumerable <Node <int> >)null, default(Node <int>), EqualityComparer <Node <int> > .Default)); Assert.Throws <ArgumentNullException>( "node", () => walker.GetDescendants((Node <int>)null, default(Node <int>)).ToArray()); Assert.Throws <ArgumentNullException>( "node", () => walker.GetDescendants((Node <int>)null, default(Node <int>), EqualityComparer <Node <int> > .Default).ToArray()); }
public void GetDescendants_ValuePredicateTests( Func <Node <int>, bool> predicate, int[] expectedResult) { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetDescendants' returns the expected results for each predicate. Assert.Equal( expectedResult, walker .GetDescendants(tree, predicate) .Select(x => x.Value)); Assert.Equal( expectedResult, walker .GetDescendants(new Node <int>[] { tree }, predicate) .Select(x => x.Value)); }
public void GetDescendants_NullPredicate_ArgumentNullExceptionThrown() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetDescendants' throws an 'ArgumentNullException' when the predicate // is null. Assert.Throws <ArgumentNullException>( "predicate", () => walker.GetDescendants(new Node <int>[] { tree }, (Func <Node <int>, int, bool>)null).ToArray()); Assert.Throws <ArgumentNullException>( "predicate", () => walker.GetDescendants(new Node <int>[] { tree }, (Func <Node <int>, bool>)null).ToArray()); Assert.Throws <ArgumentNullException>( "predicate", () => walker.GetDescendants(tree, (Func <Node <int>, int, bool>)null).ToArray()); Assert.Throws <ArgumentNullException>( "predicate", () => walker.GetDescendants(tree, (Func <Node <int>, bool>)null).ToArray()); }
public void GetDescendants_NullWalker_ArgumentNullExceptionThrown() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a null ITreeWalker. NodeWalker <int> walker = null; // Assert that 'GetDescendants' throws an 'ArgumentNullException' when the tree // walker is null. Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(new Node <int>[] { tree }, (n, i) => true).ToArray()); Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(new Node <int>[] { tree }, (n) => true).ToArray()); Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(tree, (n, i) => true).ToArray()); Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(tree, (n) => true).ToArray()); }
public void GetDescendants_ByKey_NullWalker_ArgumentNullExceptionThrown() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a null ITreeWalker. NodeWalker <int> walker = null; // Assert that 'GetDescendants' throws an 'ArgumentNullException' when the tree // walker is null. Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(new Node <int>[] { tree }, default(Node <int>))); Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(new Node <int>[] { tree }, default(Node <int>), EqualityComparer <Node <int> > .Default)); Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(tree, default(Node <int>)).ToArray()); Assert.Throws <ArgumentNullException>( "walker", () => walker.GetDescendants(tree, default(Node <int>), EqualityComparer <Node <int> > .Default).ToArray()); }
public void GetDescendants_ByKey_NullComparer() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); foreach (Node <int> key in walker.PreOrderTraversal(tree).Skip(1)) { IEnumerable <Node <int> > result = walker.GetDescendants(tree, key); Assert.Equal(1, result.Count()); Assert.Equal(key, result.First()); } }
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))); }