public void GivenValidDictionary_SetsLookupsToProvidedDictionary()
        {
            Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>
            {
                {"lookup", new List<string> {"result"}}
            };

            var engine = new SearchEngine(dict);

            var type = typeof(SearchEngine);

            var property = type.GetField("_lookupTable", BindingFlags.NonPublic | BindingFlags.Instance);

            var actual = property.GetValue(engine);

            Assert.That(actual, Is.EqualTo(dict));
        }
        static void Main()
        {
            var watch = Stopwatch.StartNew();
            Dictionary<string, List<string>> lookups = StationLookup.Get()
                .With(new FileStationSource("station-names.txt"))
                //.With(new FileStationSource("BIGdata.txt")) // Swap this with previous line for a file with 22,000 GUIDs
                .And(new DefaultStationPreprocessor());

            watch.Stop();

            Console.WriteLine("{0} lookups found in {1} miliseconds", lookups.Count, watch.ElapsedMilliseconds);

            var engine = new SearchEngine(lookups);

            while (true)
            {
                Console.WriteLine(Environment.NewLine + "Enter your search term or hit 'Ctrl' + 'C' to quit");
                var searchTerm = Console.ReadLine();

                watch = new Stopwatch();

                watch.Start();
                var result = engine.Search(searchTerm);
                watch.Stop();

                Console.WriteLine("Search completed in {0} miliseconds, {1} ticks", watch.ElapsedMilliseconds, watch.ElapsedTicks);

                if(!result.Matches.Any())
                {
                    Console.WriteLine("No matches found...");
                    continue;
                }

                Console.WriteLine("Matches: {0}", string.Join(", ", result.Matches));

                if (!result.Suggestions.Any())
                {
                    Console.WriteLine("No suggestions...");
                    continue;
                }

                Console.WriteLine("Suggestions: '{0}'", string.Join("', ", result.Suggestions));

                Console.WriteLine("Search completed in {0} miliseconds, {1} ticks", watch.ElapsedMilliseconds, watch.ElapsedTicks);
            }
        }
        public void GivenA_ReturnsNoMatches()
        {
            Dictionary<string, List<string>> lookups = new Dictionary<string, List<string>>
            {
                {"lookup", new List<string> {"result"}}
            };

            var engine = new SearchEngine(lookups);

            var result = engine.Search("a");

            Assert.That(result.Matches, Is.Empty);
        }
        public void GivenWhitespace_ReturnsNoSuggestions()
        {
            Dictionary<string, List<string>> lookups = new Dictionary<string, List<string>>
            {
                {"lookup", new List<string> {"result"}}
            };

            var engine = new SearchEngine(lookups);

            var result = engine.Search("   \t\t\n   ");

            Assert.That(result.Suggestions, Is.Empty);
        }
        public void GivenL_ReturnsResult()
        {
            Dictionary<string, List<string>> lookups = new Dictionary<string, List<string>>
            {
                {"l", new List<string> {"result"}},
                {"lo", new List<string> {"result"}},
                {"loo", new List<string> {"result"}},
                {"look", new List<string> {"result"}},
                {"looku", new List<string> {"result"}},
                {"lookup", new List<string> {"result"}},
            };

            var engine = new SearchEngine(lookups);

            var result = engine.Search("l");

            Assert.That(result.Matches.Single(), Is.EqualTo("result"));
        }
        public void GivenL_Returns1Suggestion()
        {
            Dictionary<string, List<string>> lookups = new Dictionary<string, List<string>>
            {
                {"l", new List<string> {"result"}},
                {"lo", new List<string> {"result"}},
                {"loo", new List<string> {"result"}},
                {"look", new List<string> {"result"}},
                {"looku", new List<string> {"result"}},
                {"lookup", new List<string> {"result"}},
            };

            var engine = new SearchEngine(lookups);

            var result = engine.Search("l");

            Assert.That(result.Suggestions.Count, Is.EqualTo(1));
        }
        public void GivenLWith3Matches_ReturnsO()
        {
            Dictionary<string, List<string>> lookups = new Dictionary<string, List<string>>
            {
                {"l", new List<string> {"lookup", "lol", "link"}}
            };

            var engine = new SearchEngine(lookups);

            var result = engine.Search("l");

            Assert.That(result.Suggestions.Count(x => x.Equals('o')), Is.EqualTo(1));
        }