public void TreeManipulationTest() { Tree<CityTreeNode> tree = new CityTreeBuilder() .GetData() .LoadTree() .Build(); Assert.IsNotNull(tree, "Shouldn't be null"); Assert.AreEqual(tree.CurrentNode, tree.Root, "Should be equal at start."); Assert.IsNotNull(tree.Search("kom"), "Should be able to find node."); try { tree.AddNode(string.Empty, null); Assert.Fail("Shouldn't be able to add empty name node."); } catch (ArgumentNullException) { Assert.IsTrue(true); } }
/// <summary> /// Runs de test program /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { Tree<CityTreeNode> tree = new CityTreeBuilder() .GetData() .LoadTree() .Build(); Stopwatch s1 = Stopwatch.StartNew(); while (true) { Console.WriteLine("Please type the city you want: (press enter after each character)"); var result = Console.ReadLine(); List<int> lst = new List<int>(); s1.Restart(); var searchNode = tree.Search(result.ToLower()); if (searchNode == null) { Console.WriteLine("No results found."); continue; } AutoCompleteResult possibleResults = searchNode.GetPossibleResults(); if (possibleResults == null) { Console.WriteLine("No possible results found."); continue; } s1.Stop(); Console.WriteLine(possibleResults.ToString()); Console.WriteLine("Do another search."); Console.WriteLine("Time taken: {0}ms on 3000 results", s1.ElapsedMilliseconds); } }