public void Sum() { var tree = new TreeOf(); tree.Put(5) .Put(3) .Put(2) .Put(1); int result = tree.Sum(); Assert.Equal(11, result); }
public void GetMinRecursive() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(4) .Put(3) .Put(2) .Put(8) .Put(1); Assert.Equal(1, tree.GetMinRecursive()); }
public void Postorder() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(4); var result = new List <int>(); tree.Postorder(result.Add); Assert.Equal(new[] { 4, 7, 5 }, result); }
public void BottomView() { var tree = new TreeOf(); tree.Put(20) .Put(30) .Put(25) .Put(40) .Put(10) .Put(8) .Put(15); List<int> result = tree.BottomView(); Assert.Equal(new[] { 25, 10, 8, 30, 40 }, result); }
public void Preoder() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(4); var result = new List <int>(); tree.Preoder(result.Add); Assert.Equal(new[] { 5, 4, 7 }, result); }
public void FindDeeppest() { var tree = new TreeOf(); tree.Put(20) .Put(30) .Put(25) .Put(40) .Put(10) .Put(8) .Put(15) .Put(50); int result = tree.FindDeeppest(); Assert.Equal(3, result); }
public void AddAllGreaterValuesToEveryNode() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(3) .Put(6) .Put(8) .Put(2) .Put(4); tree.AddAllGreaterValuesToEveryNode(); List<int> result = tree.Select(x => x).ToList(); Assert.Equal(new[] { 26, 33, 35, 30, 15, 21, 8 }, result); }
public void BottomView() { var tree = new TreeOf(); tree.Put(20) .Put(30) .Put(25) .Put(40) .Put(10) .Put(8) .Put(15); List <int> result = tree.BottomView(); Assert.Equal(new[] { 25, 10, 8, 30, 40 }, result); }
public void IsBinarySearchTree() { var tree = new TreeOf(); tree.Put(20) .Put(30) .Put(25) .Put(40) .Put(10) .Put(8) .Put(15); bool result = tree.IsBinarySearchTree(); Assert.True(result); }
public void AddAllGreaterValuesToEveryNode() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(3) .Put(6) .Put(8) .Put(2) .Put(4); tree.AddAllGreaterValuesToEveryNode(); List <int> result = tree.Select(x => x).ToList(); Assert.Equal(new[] { 26, 33, 35, 30, 15, 21, 8 }, result); }
public void HasPathSumBySum() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(4) .Put(3) .Put(2) .Put(8) .Put(1); bool result = tree.HasPathSumBySum(20); Assert.True(result); result = tree.HasPathSumBySum(21); Assert.False(result); }
public void VerticalSum() { var tree = new TreeOf(); tree.Put(6) .Put(8) .Put(4) .Put(3) .Put(5) .Put(7) .Put(9); Dictionary <int, int> result = tree.VerticalSum(); var expected = new Dictionary <int, int> { { 0, 18 }, { -1, 4 }, { -2, 3 }, { 1, 8 }, { 2, 9 } }; Assert.Equal(expected, result); }
public void Postorder() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(4); var result = new List<int>(); tree.Postorder(result.Add); Assert.Equal(new[] { 4, 7, 5 }, result); }
public void Preoder() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(4); var result = new List<int>(); tree.Preoder(result.Add); Assert.Equal(new[] { 5, 4, 7 }, result); }
public void VerticalSum() { var tree = new TreeOf(); tree.Put(6) .Put(8) .Put(4) .Put(3) .Put(5) .Put(7) .Put(9); Dictionary<int, int> result = tree.VerticalSum(); var expected = new Dictionary<int, int> { { 0, 18 }, { -1, 4 }, { -2, 3 }, { 1, 8 }, { 2, 9 } }; Assert.Equal(expected, result); }
public void HasPathSumBySubtract() { var tree = new TreeOf(); tree.Put(5) .Put(7) .Put(4) .Put(3) .Put(2) .Put(8) .Put(1); bool result = tree.HasPathSumBySubtract(20); Assert.True(result); result = tree.HasPathSumBySubtract(21); Assert.False(result); }