public void Test1(int[] bstArray, bool expectedResult)
        {
            BSTTreeNode root = BinarySearchTreeGenerator.GenerateFromArray(bstArray, false);

            BinarySearchTreeValidationSolution solution = new BinarySearchTreeValidationSolution();
            bool result = solution.Solve(root);

            result.Should().Be(expectedResult);
        }
示例#2
0
        public void Test1(int[] bstArray, int[] expectedResult)
        {
            BSTTreeNode root = BinarySearchTreeGenerator.GenerateFromArray(bstArray, false);

            FindModeInBinarySearchTreeSolution solution = new FindModeInBinarySearchTreeSolution();

            int[] result = solution.Solve(root);

            result.Should().NotBeNull();
            result.Length.Should().Be(expectedResult.Length);
            //Assuming that the expectedResult array will be sorted
            for (int i = 0; i < result.Length; i++)
            {
                result[i].Should().Be(expectedResult[i]);
            }
        }
示例#3
0
        public void Test3(int k, int expectedResult)
        {
            int[] array =
            {
                45, 30, 46, 10, 36, -1, 49,  8, 24, 34, 42, 48, -1,  4,  9, 14, 25, 31, 35, 41, 43, 47, -1,  0,  6, -1, -1,
                11, 20, -1, 28, -1, 33, -1, -1, 37, -1, -1, 44, -1, -1, -1,  1,  5,  7, -1, 12, 19, 21, 26, 29, 32, -1, -1,
                38, -1, -1, -1,  3, -1, -1, -1, -1, -1, 13, 18, -1, -1, 22, -1, 27, -1, -1, -1, -1, -1, 39,  2, -1, -1,
                -1, 15, -1, -1, 23, -1, -1, -1, 40, -1, -1, -1, 16, -1, -1, -1, -1, -1, 17
            };

            BSTTreeNode root = BinarySearchTreeGenerator.GenerateFromArray(array);

            KthSmallestElementSolution solution = new KthSmallestElementSolution();
            int result = solution.Solve(root, k);

            result.Should().Be(expectedResult);
        }