public void BuildWFTest()
        {
            CityTreeBuilder cs = new CityTreeBuilder();

            Assert.IsNotNull(cs.GetData(), "Shoudn't be null");
            try
            {
                new CityTreeBuilder().LoadTree();
                Assert.Fail("Shouldn't be able to load tree when data is not loaded");
            }
            catch (NullReferenceException)
            {
                Assert.IsTrue(true);
            }

            try
            {
                new CityTreeBuilder().Build();
                Assert.Fail("Shouldn't be able to build tree when data and tree is not loaded");
            }
            catch (NullReferenceException)
            {
                Assert.IsTrue(true);
            }

            Assert.IsNotNull(cs.GetData().LoadTree().Build(), "Shoudn't be null");
        }
        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);
            }
        }
예제 #3
0
        /// <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);
            }
        }