Example #1
0
        public void GetLeaves_NullNode_ArgumentNullExceptionThrown()
        {
            // Create a valid ITreeWalker.
            NodeWalker <int> walker = new NodeWalker <int>();

            // Assert that 'GetLeaves' throws an 'ArgumentNullException' when the node is null.
            Assert.Throws <ArgumentNullException>("node", () => walker.GetLeaves(null).ToArray());
        }
Example #2
0
        public void GetLeaves_NullWalker_ArgumentNullExceptionThrown()
        {
            // Get a valid tree.
            var tree = TestTreeFactory.GetSimpleTree();

            // Create a null ITreeWalker.
            NodeWalker <int> walker = null;

            // Assert that 'GetLeaves' throws an 'ArgumentNullException' when the tree walker
            // is null.
            Assert.Throws <ArgumentNullException>("walker", () => walker.GetLeaves(tree).ToArray());
        }
Example #3
0
        public void GetLeaves(int[] testPath, int[] expected)
        {
            // Get a valid tree.
            var tree = TestTreeFactory.GetSimpleTree();

            // Get a valid ITreeWalker.
            NodeWalker <int> walker = new NodeWalker <int>();

            var node = tree;

            foreach (int i in testPath)
            {
                node = walker.GetChildAt(node, i);
            }

            Assert.Equal(
                expected,
                walker.GetLeaves(node).Select(x => x.Value));
        }
        public void GetBranches_MultipleBranches()
        {
            // Get a valid tree.
            var tree = TestTreeFactory.GetSimpleTree();

            // Get a valid ITreeWalker.
            NodeWalker <int> walker = new NodeWalker <int>();

            // Assert.
            Assert.Equal(
                walker
                .GetLeaves(tree)
                .Select(x =>
                        EnumerableEx
                        .Return(x)
                        .Concat(walker.GetAncestors(x))
                        .Reverse()
                        .ToArray())
                .ToArray(),
                walker.GetBranches(tree).Select(x => x.ToArray()).ToArray());
        }