public void BinaryTreeScapegoatIndexAccess1() { ScapegoatTree <int, int> tree = new ScapegoatTree <int, int>(); List <int> inputs = Enumerable.Range(1, 10).ToList(); this.TestOrderPreservationOnInsertStructs <IBinaryTreeNode <int, int>, int>(inputs, tree); for (int i = 0; i < 10; i++) { Assert.AreEqual(inputs[i], tree.GetValueAt(i)); } // Swap the values using index access for (int i = 0, j = 9; i < j; i++, j--) { int temp = tree.GetValueAt(i); tree.SetValueAt(i, tree.GetValueAt(j)); tree.SetValueAt(j, temp); } TestTools.PrintEnumerableStruct(tree.Values, ","); for (int i = 0; i < 10; i++) { Assert.AreEqual(10 - i, tree.GetValueAt(i)); } }
public void BinaryTreeScapegoatIndexAccess2() { ScapegoatTree <int, int> tree = new ScapegoatTree <int, int>(); List <int> inputs = Enumerable.Range(1, 10).ToList(); this.TestOrderPreservationOnInsertStructs <IBinaryTreeNode <int, int>, int>(inputs, tree); for (int i = 0; i < 10; i++) { Assert.AreEqual(inputs[i], tree.GetValueAt(i)); } // Remove values in random order while (tree.Root != null) { int index = this._rnd.Next(tree.Root.Size); tree.RemoveAt(index); inputs.RemoveAt(index); this.TestOrderStructs(inputs, tree.Keys.ToList()); } }