public void CountPathsWithSumTest(int testSum, int expectedCount) { // Arrange var root = new BinaryTreeNode <int>(10) { Left = new BinaryTreeNode <int>(5) { Left = new BinaryTreeNode <int>(3) { Left = new BinaryTreeNode <int>(3), Right = new BinaryTreeNode <int>(-2) }, Right = new BinaryTreeNode <int>(2) { Right = new BinaryTreeNode <int>(1) } }, Right = new BinaryTreeNode <int>(-3) { Right = new BinaryTreeNode <int>(11) } }; // Act int resultCount1 = Question_4_12.CountPathsWithSum(root, testSum); int resultCount2 = Question_4_12.CountPathsWithSumOptimized(root, testSum); // Assert Assert.AreEqual(expectedCount, resultCount1, "Count 1 is incorrect."); Assert.AreEqual(expectedCount, resultCount2, "Count 2 is incorrect - optimized method."); }
private static void Validate(int expectedPathCount, BinaryTreeNode <int> root, int target) { var result = Question_4_12.SumPaths(root, target); Assert.AreEqual(expectedPathCount, result); }