public void Add_KeyAlreadyInTree_ThrowsException() { var tree = new AaTree <int>(); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); Assert.Throws <ArgumentException>(() => tree.Add(1)); }
public void GetMin_NonEmptyTree_ReturnsCorrectAnswer() { var tree = new AaTree <int>(); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); tree.GetMin().Should().Be(1); }
public void GetKeysInOrder_NonEmptyTree_ReturnsCorrectAnswer() { var tree = new AaTree <int>(); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); tree.GetKeysInOrder().SequenceEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).Should().BeTrue(); }
public void Remove_EmptyTree_Throws() { var tree = new AaTree <int>(); Action act = () => tree.Remove(999); act.Should().Throw <InvalidOperationException>(); }
public void Contains_NonEmptyTree_ReturnsCorrectAnswer() { var tree = new AaTree <int>(); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); tree.Contains(6).Should().BeTrue(); tree.Contains(999).Should().BeFalse(); }
public void Remove_KeyNotInTree_Throws() { var tree = new AaTree <int>(); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); Action act = () => tree.Remove(999); act.Should().Throw <InvalidOperationException>(); }
public void AddRange_MultipleKeys_FormsCorrectTree() { var tree = new AaTree <int>(); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); tree.Count.Should().Be(10); tree.GetKeysInOrder().SequenceEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).Should().BeTrue(); tree.GetKeysPostOrder().SequenceEqual(new[] { 1, 3, 2, 5, 7, 10, 9, 8, 6, 4 }).Should().BeTrue(); Validate(tree.Root); }
public void Constructor_UseCustomComparer_FormsCorrectTree() { var tree = new AaTree <int>(Comparer <int> .Create((x, y) => y.CompareTo(x))); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); tree.GetMax().Should().Be(1); tree.GetMin().Should().Be(10); tree.GetKeysInOrder().SequenceEqual(new[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }).Should().BeTrue(); Validate(tree.Root); }
static void Main(string[] args) { var tree = new AaTree<int, string>(); Console.WriteLine("The AA tree created."); var nums = new[] { -5, 20, 14, 11, 8, -3, 111, 7, 100, -55 }; for (int i = 0; i < nums.Length; i++) { tree.Add(nums[i], "value"); } }
public void Add_MultipleKeys_FormsCorrectTree() { var tree = new AaTree <int>(); foreach (var elem in new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) { tree.Add(elem); tree.Count.Should().Be(elem); tree.Contains(elem).Should().BeTrue(); } tree.GetKeysInOrder().SequenceEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).Should().BeTrue(); tree.GetKeysPostOrder().SequenceEqual(new[] { 1, 3, 2, 5, 7, 10, 9, 8, 6, 4 }).Should().BeTrue(); Validate(tree.Root); }
public void Remove_MultipleKeys_TreeStillValid() { var tree = new AaTree <int>(); tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); Remove(4).Should().NotThrow(); tree.Contains(4).Should().BeFalse(); tree.Count.Should().Be(9); Remove(8).Should().NotThrow(); tree.Contains(8).Should().BeFalse(); tree.Count.Should().Be(8); Remove(1).Should().NotThrow(); tree.Contains(1).Should().BeFalse(); tree.Count.Should().Be(7); Validate(tree.Root); Action Remove(int x) => () => tree.Remove(x); }
public void GetKeysPostOrder_EmptyTree_ReturnsCorrectAnswer() { var tree = new AaTree <int>(); tree.GetKeysPostOrder().ToList().Count.Should().Be(0); }
public void GetMin_EmptyTree_ThrowsCorrectException() { var tree = new AaTree <int>(); Assert.Throws <InvalidOperationException>(() => tree.GetMin()); }
public void Contains_EmptyTree_ReturnsFalse() { var tree = new AaTree <int>(); tree.Contains(999).Should().BeFalse(); }