public void InsertionAndDeletionPUT([PexAssumeUnderTest] List <int> values, int start, int end) { PexAssume.IsFalse(start < 0 || end < 0); PexAssume.IsTrue(start < values.Count); PexAssume.IsTrue(end >= start && end < values.Count); PexAssume.AreDistinctValues <int>(values.ToArray()); AvlTree <int> avlTree = new AvlTree <int>(); foreach (int i in values) { avlTree.Add(i); } PexAssert.AreEqual(values.Count, avlTree.Count); PexObserve.ValueForViewing <int>("Root", avlTree.Root.Value); int toRemoveCount = (end - start) == 0?1:end - start; IList <int> toRemove = values.GetRange(start, toRemoveCount); foreach (int i in toRemove) { avlTree.Remove(i); } PexAssert.AreEqual(values.Count - toRemoveCount, avlTree.Count); IEnumerable enumerator = avlTree.GetInorderEnumerator(); foreach (int i in enumerator) { PexObserve.ValueForViewing <int>("tree nodes", i); } }
public void TraversalPUT([PexAssumeUnderTest] List <int> values) { PexAssume.AreDistinctValues <int>(values.ToArray()); AvlTree <int> avlTree = new AvlTree <int> (values); List <int> actual = new List <int>(); foreach (int value in avlTree.GetInorderEnumerator()) { actual.Add(value); } values.Sort(); CollectionAssert.AreEqual(values, actual); }
public void InsertionMassivePUT([PexAssumeUnderTest] List <int> values) { PexAssume.IsTrue(values.Count > 0); AvlTree <int> avlTree = new AvlTree <int>(); foreach (int i in values) { avlTree.Add(i); } PexAssert.AreEqual(values.Count, avlTree.Count); IEnumerable enumerator = avlTree.GetInorderEnumerator(); foreach (int i in enumerator) { PexObserve.ValueForViewing <int>("tree nodes", i); } }
static void Main(string[] args) { AvlTree <int> tree = new AvlTree <int>(); for (int i = 1; i < 10; i++) { tree.Add(i); } Console.WriteLine("In-order: " + string.Join(", ", tree.GetInorderEnumerator())); Console.WriteLine("Post-order: " + string.Join(", ", tree.GetPostorderEnumerator())); Console.WriteLine("Breadth-first: " + string.Join(", ", tree.GetBreadthFirstEnumerator())); AvlTreeNode <int> node = tree.FindNode(8); Console.WriteLine($"Children of node {node.Value} (height = {node.Height}): {node.Left.Value} and {node.Right.Value}."); }
public void TraversalTest() { AvlTree <int> avlTree = new AvlTree <int> { 10, 20, 30 }; List <int> expected = new List <int> { 10, 20, 30 }; List <int> actual = new List <int>(); foreach (int value in avlTree.GetInorderEnumerator()) { actual.Add(value); } for (int i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i], actual[i]); } }
public void RemoveTreePUT([PexAssumeUnderTest] List <int> values, int start, int end) { PexAssume.IsFalse(start < 0 || end < 0); PexAssume.IsTrue(start < values.Count); PexAssume.IsTrue(end >= start && end < values.Count); AvlTree <int> avlTree = new AvlTree <int>(values); int toRemoveCount = (end - start) == 0 ? (values.Count > 0? 1:0) : end - start; IList <int> toRemove = values.GetRange(start, toRemoveCount); foreach (int i in toRemove) { bool result = avlTree.Remove(i); PexAssert.IsTrue(result); } PexAssert.AreEqual(values.Count - toRemoveCount, avlTree.Count); IEnumerable enumerator = avlTree.GetInorderEnumerator(); foreach (int i in enumerator) { PexObserve.ValueForViewing <int>("tree nodes", i); } }
public void TraversalTest() { AvlTree<int> avlTree = new AvlTree<int> { 10, 20, 30 }; List<int> expected = new List<int> { 10, 20, 30 }; List<int> actual = new List<int>(); foreach (int value in avlTree.GetInorderEnumerator()) { actual.Add(value); } for (int i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i], actual[i]); } }
public void TraversalPUT([PexAssumeUnderTest]List<int> values) { PexAssume.AreDistinctValues<int>(values.ToArray()); AvlTree<int> avlTree = new AvlTree<int> (values); List<int> actual = new List<int>(); foreach (int value in avlTree.GetInorderEnumerator()) { actual.Add(value); } values.Sort(); CollectionAssert.AreEqual(values, actual); }
public void RemoveTreePUT([PexAssumeUnderTest]List<int> values, int start, int end) { PexAssume.IsFalse(start < 0 || end < 0); PexAssume.IsTrue(start < values.Count); PexAssume.IsTrue(end >= start && end < values.Count); AvlTree<int> avlTree = new AvlTree<int>(values); int toRemoveCount = (end - start) == 0 ? (values.Count > 0? 1:0) : end - start; IList<int> toRemove = values.GetRange(start, toRemoveCount); foreach (int i in toRemove) { bool result = avlTree.Remove(i); PexAssert.IsTrue(result); } PexAssert.AreEqual(values.Count - toRemoveCount, avlTree.Count); IEnumerable enumerator = avlTree.GetInorderEnumerator(); foreach (int i in enumerator) PexObserve.ValueForViewing<int>("tree nodes", i); }
public void InsertionMassivePUT([PexAssumeUnderTest]List<int> values) { PexAssume.IsTrue(values.Count > 0); AvlTree<int> avlTree = new AvlTree<int>(); foreach (int i in values) { avlTree.Add(i); } PexAssert.AreEqual(values.Count, avlTree.Count); IEnumerable enumerator = avlTree.GetInorderEnumerator(); foreach (int i in enumerator) PexObserve.ValueForViewing<int>("tree nodes", i); }
public void InsertionAndDeletionPUT([PexAssumeUnderTest]List<int> values, int start, int end) { PexAssume.IsFalse(start < 0 || end < 0); PexAssume.IsTrue(start < values.Count); PexAssume.IsTrue(end >= start && end < values.Count); PexAssume.AreDistinctValues<int>(values.ToArray()); AvlTree<int> avlTree = new AvlTree<int>(); foreach(int i in values) avlTree.Add(i); PexAssert.AreEqual(values.Count, avlTree.Count); PexObserve.ValueForViewing<int>("Root", avlTree.Root.Value); int toRemoveCount = (end - start)==0?1:end-start; IList<int> toRemove = values.GetRange(start, toRemoveCount); foreach (int i in toRemove) avlTree.Remove(i); PexAssert.AreEqual(values.Count - toRemoveCount, avlTree.Count); IEnumerable enumerator = avlTree.GetInorderEnumerator(); foreach(int i in enumerator) PexObserve.ValueForViewing<int>("tree nodes",i); }