public void GetChildrenByPredicate_NullNode_ArgumentNullExceptionThrown() { // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetChildren' throws an 'ArgumentNullException' when the node is // null. Assert.Throws <ArgumentNullException>( "nodes", () => walker.GetChildren((IEnumerable <Node <int> >)null, (n) => true).ToArray()); Assert.Throws <ArgumentNullException>( "node", () => walker.GetChildren((Node <int>)null, (n) => true).ToArray()); }
public void GetChildrenByPredicate_NullPredicate_ArgumentNullExceptionThrown() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetChildren' throws an 'ArgumentNullException' when the predicate // is null. Assert.Throws <ArgumentNullException>( "predicate", () => walker.GetChildren(new Node <int>[] { tree }, (Func <Node <int>, bool>)null).ToArray()); Assert.Throws <ArgumentNullException>( "predicate", () => walker.GetChildren(tree, (Func <Node <int>, bool>)null).ToArray()); }
public void GetChildrenByPredicate_NullWalker_ArgumentNullExceptionThrown() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a null ITreeWalker. NodeWalker <int> walker = null; // Assert that 'GetChildren' throws an 'ArgumentNullException' when the tree // walker is null. Assert.Throws <ArgumentNullException>( "walker", () => walker.GetChildren(new Node <int>[] { tree }, (n) => true).ToArray()); Assert.Throws <ArgumentNullException>( "walker", () => walker.GetChildren(tree, (n) => true).ToArray()); }
public void GetChildrenByKey_NullNode_ArgumentNullExceptionThrown() { // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetChildren' throws an 'ArgumentNullException' when the node is // null. Assert.Throws <ArgumentNullException>( "nodes", () => walker.GetChildren((IEnumerable <Node <int> >)null, default(Node <int>)).ToArray()); Assert.Throws <ArgumentNullException>( "node", () => walker.GetChildren((Node <int>)null, default(Node <int>)).ToArray()); Assert.Throws <ArgumentNullException>( "nodes", () => walker.GetChildren((IEnumerable <Node <int> >)null, default(Node <int>), EqualityComparer <Node <int> > .Default).ToArray()); Assert.Throws <ArgumentNullException>( "node", () => walker.GetChildren((Node <int>)null, default(Node <int>), EqualityComparer <Node <int> > .Default).ToArray()); }
public void GetChildrenByPredicate_PredicateTests() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Create test predicates and the expected results. var testCases = new[] { new { Predicate = new Func <Node <int>, bool>(i => i.Value % 2 == 0), ExpectedResults = new int[] { 4 } }, new { Predicate = new Func <Node <int>, bool>(i => i.Value % 2 == 1), ExpectedResults = new int[] { 1 } }, new { Predicate = new Func <Node <int>, bool>(i => i.Value >= 2), ExpectedResults = new int[] { 4 } }, }; // Assert that 'GetChildren' returns the expected results for each predicate. foreach (var testCase in testCases) { Assert.Equal( walker .GetChildren(tree, testCase.Predicate) .Select(x => x.Value), testCase.ExpectedResults); Assert.Equal( walker .GetChildren(new Node <int>[] { tree }, testCase.Predicate) .Select(x => x.Value), testCase.ExpectedResults); } }
public void GetChildrenByKey_NullKey_ArgumentNullExceptionThrown() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); // Assert that 'GetChildren' throws an 'ArgumentNullException' when the key // is null. Assert.Throws <ArgumentNullException>( "key", () => walker.GetChildren(new Node <int>[] { tree }, (Node <int>)null).ToArray()); Assert.Throws <ArgumentNullException>( "key", () => walker.GetChildren(tree, (Node <int>)null).ToArray()); Assert.Throws <ArgumentNullException>( "key", () => walker.GetChildren(new Node <int>[] { tree }, (Node <int>)null, EqualityComparer <Node <int> > .Default).ToArray()); Assert.Throws <ArgumentNullException>( "key", () => walker.GetChildren(tree, (Node <int>)null, EqualityComparer <Node <int> > .Default).ToArray()); }
public void GetChildrenByKey_ByKeyTests() { // Get a valid tree. var tree = TestTreeFactory.GetSimpleTree(); // Create a valid ITreeWalker. NodeWalker <int> walker = new NodeWalker <int>(); foreach (Node <int> node in walker.PreOrderTraversal(tree)) { foreach (Node <int> key in walker.PreOrderTraversal(tree)) { IEnumerable <Node <int> > result = walker.GetChildren(node, key).ToArray(); if (walker.GetChildren(node).Contains(key)) { Assert.Equal(result, new Node <int>[] { key }); } else { Assert.Empty(result); } } } }