public void TestTreeSetString() { var set = new TreeSet <string>(StringComparer.InvariantCultureIgnoreCase); string[] contents = { "water supply", "Threat", "emergency", "admiration", "public relations", "lignite", "water vapor", "Tranquilizer", "insurrectionist", "Threatened", "Cocaine", "water level", "neuromuscular", "Proton Magnetic Resonance", "Recession", "treacherous", "carbon monoxide poisoning" }; foreach (var s in contents) { set.Add(s); } string prefix = "t"; int count = 0; foreach (var item in set.CreateWindow("t", "tZZZZZZZ")) { Console.WriteLine(item); count++; } Assert.AreEqual(4, count); }
public void TestTreeSetStartEnd() { int[] contents = new[] { 2, 4, 7, 8, 12, 14, 16, 18, 19, 23, 27, 35, 37, 40 }; var treeSet = new TreeSet <int>(); for (int index = 0; index < contents.Length; index++) { treeSet.Add(contents[index]); } Assert.AreEqual(contents.Length, treeSet.Count); for (int i = 0; i < 50; i++) { int expectedStart = -1, expectedEnd = -1; int j = 0; while (j < contents.Length && contents[j] < i) { j++; } if (j < contents.Length) { expectedStart = contents[j]; } j = contents.Length - 1; while (j >= 0 && contents[j] > i) { j--; } if (j >= 0) { expectedEnd = contents[j]; } var startNode = treeSet.FindStartNode(i); var stopNode = treeSet.FindEndNode(i); int actualStart = startNode == null ? -1 : startNode.Item; int actualEnd = stopNode == null ? -1 : stopNode.Item; Assert.AreEqual(expectedStart, actualStart); Assert.AreEqual(expectedEnd, actualEnd); } for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { int actualCount = 0, last = -1; foreach (int x in treeSet.CreateWindow(i, j)) { Assert.IsTrue(x > last); Assert.IsTrue(Array.IndexOf(contents, x) >= 0); last = x; actualCount++; } int expectedCount = 0; foreach (int x in contents) { if (x >= i && x <= j) { expectedCount++; } } Assert.AreEqual(expectedCount, actualCount); } } }