public async Task add_entry_to_index_that_is_in_conflict_throws_exception_if_exception_enabled()
        {
            var customer = new Customer
            {
                Email     = "*****@*****.**",
                FirstName = "Bill",
                LastName  = "Gates",
                Id        = "2000"
            };

            var index = new TrieSearch <Customer>("trieUnitTestsConflictTest", "UseDevelopmentStorage=true", c => c.Id, options:
                                                  new TrieSearchOptions {
                ThrowOnConflict = true
            });

            bool exceptionThrown = false;

            try
            {
                await index.IndexAsync(customer, "Gates");

                await index.IndexAsync(customer, "Gates");
            }
            catch (Exception ex)
            {
                exceptionThrown = true;
            }
            finally
            {
                await index.DropIndexAsync();
            }

            Assert.IsTrue(exceptionThrown);
        }
        public async Task add_entry_to_index_beyond_maximum_length_does_not_get_indexed_beyond_maximum_if_exceptions_are_disabled()
        {
            var customer = new Customer
            {
                Email     = "*****@*****.**",
                FirstName = "Bill",
                LastName  = "Gates",
                Id        = "2000"
            };

            var index = new TrieSearch <Customer>("trieUnitTestsMaxLenTest", "UseDevelopmentStorage=true", c => c.Id, options:
                                                  new TrieSearchOptions {
                MaximumIndexLength = 3
            });


            try
            {
                await index.IndexAsync(customer, "Gates");

                var results = await index.FindAsync("gat");

                Assert.AreEqual(1, results.Count());

                results = await index.FindAsync("gates");

                Assert.AreEqual(0, results.Count());
            }
            finally
            {
                await index.DropIndexAsync();
            }
        }
        public async Task add_entry_to_index_beyond_maximum_length_throws_exception_if_exceptions_enabled()
        {
            var customer = new Customer
            {
                Email     = "*****@*****.**",
                FirstName = "Bill",
                LastName  = "Gates",
                Id        = "2000"
            };

            var index = new TrieSearch <Customer>("trieUnitTestsMaxLenTest", "UseDevelopmentStorage=true", c => c.Id, options:
                                                  new TrieSearchOptions {
                MaximumIndexLength = 3, ThrowOnMaximumIndexLengthExceeded = true
            });

            bool exceptionThrown = false;

            try
            {
                await index.IndexAsync(customer, "Gates");
            }
            catch (ArgumentException ex)
            {
                exceptionThrown = true;
            }
            finally
            {
                await index.DropIndexAsync();
            }

            Assert.IsTrue(exceptionThrown);
        }
        public async Task add_entry_to_index_throws_exception_when_minumum_not_met_and_exceptions_are_enabled()
        {
            var customer = new Customer
            {
                Email     = "*****@*****.**",
                FirstName = "Bill",
                LastName  = "Gates",
                Id        = "2000"
            };

            var failIndex = new TrieSearch <Customer>("trieUnitTestsFailTest", "UseDevelopmentStorage=true", c => c.Id, options:
                                                      new TrieSearchOptions {
                ThrowOnMinimumIndexLengthNotMet = true, MinimumIndexLength = 3
            });

            bool exceptionThrown = false;

            try
            {
                await failIndex.IndexAsync(customer, "b");
            }
            catch (ArgumentException e)
            {
                exceptionThrown = true;
            }
            finally
            {
                await failIndex.DropIndexAsync();
            }

            Assert.IsTrue(exceptionThrown);
        }
        public async Task Init()
        {
            _fullNameIndex = new TrieSearch <Customer>("trieUnitTestFullNameIndex", "UseDevelopmentStorage=true", c => c.Id, 10);
            _lastNameIndex = new TrieSearch <Customer>("trieUnitTestLastNameIndex", "UseDevelopmentStorage=true", c => c.Id, 10);
            _emailIndex    = new TrieSearch <Customer>("trieUnitTestEmailIndex", "UseDevelopmentStorage=true", c => c.Id, 10,
                                                       new TrieSearchOptions
            {
                MinimumIndexLength = 3
            });
            _multiIndexSearch = new MultiIndexTrieSearch <Customer>(new Dictionary <ITrieSearch <Customer>, Func <Customer, string> >
            {
                [_fullNameIndex] = c => c.FirstName + " " + c.LastName,
                [_lastNameIndex] = c => c.LastName,
                [_emailIndex]    = c => c.Email
            });

            _dedupeFunction = customers =>
            {
                var uniqueIds       = customers.Select(c => c.Id).Distinct();
                var uniqueCustomers = new List <Customer>();
                foreach (var id in uniqueIds)
                {
                    uniqueCustomers.Add(customers.First(c => c.Id == id));
                }

                return(uniqueCustomers);
            };

            await CreateTestData();
        }
Exemplo n.º 6
0
        public void TestLoadTrieWithAWordWithSpecialCharacter()
        {
            List <string> words = new List <string> {
                "pygobranchiate",
                "/pygofer",
                "pygopagus",
                "pygopod",
                "pygopodine",
                "pygopodous",
                "pygostyle",
                "pygostyled",
                "pygos/tylous",
                "pyic",
                "pyin",
                "pyin/s",
                "pyjama/",
                "pyjamaed",
                "pyjamas"
            };

            TrieSearch    trie        = new TrieSearch(words);
            List <string> resultWords = trie.GetWordsForPrefix("PY");

            Assert.AreEqual(words.Count, resultWords.Count);

            Assert.IsTrue(trie.IsPrefixAWord("pygofer".ToUpper()));
            Assert.IsTrue(trie.IsPrefixAWord("pygostylous".ToUpper()));
            Assert.IsTrue(trie.IsPrefixAWord("pyins".ToUpper()));
            Assert.IsTrue(trie.IsPrefixAWord("pyjama".ToUpper()));
        }
Exemplo n.º 7
0
        public void TestLoadTrieWithOneDuplicateWord()
        {
            List <string> words = new List <string> {
                "pygobranchiate",
                "pygofer",
                "pygopagus",
                "pygopod",
                "pygopodine",
                "pygopodous",
                "pygostyle",
                "pygostyled",
                "pygostylous",
                "pyic",
                "pyin",
                "pyins",
                "pyjama",
                "pyjama",
                "pyjamaed",
                "pyjamas"
            };

            TrieSearch    trie        = new TrieSearch(words);
            List <string> resultWords = trie.GetWordsForPrefix("");

            Assert.AreEqual(words.Count - 1, resultWords.Count);
        }
Exemplo n.º 8
0
        public void TestReturnedWinningWords()
        {
            List <string> words = new List <string> {
                "pygobranchiate",
                "pygofer",
                "pygopagus",
                "pygopod",
                "pygopodine",
                "pygopodous",
                "pygostyle",
                "pygostyled",
                "pygostylous",
                "pyic",
                "pyin",
                "pyins",
                "pyjama",
                "pyjamaed",
                "pyjamas"
            };

            TrieSearch    trie        = new TrieSearch(words);
            List <string> resultWords = trie.GetWinningWords("PYG");

            Assert.IsTrue(resultWords.Count == 5);
        }
Exemplo n.º 9
0
        public void TestWordContainsOddWord()
        {
            List <string> words = new List <string> {
                "pygobranchiate",
                "pygofer",
                "pygopagus",
                "pygopod",
                "pygopodine",
                "pygopodous",
                "pygostyle",
                "pygostyled",
                "pygostylous",
                "pyic",
                "pyin",
                "pyins",
                "pyjama",
                "pyjamaed",
                "pyjamas"
            };

            TrieSearch trie   = new TrieSearch(words);
            bool       result = trie.ContainsAnOddWordInsideWithLengthGreaterThan("PYJAMAS", 3);

            Assert.IsTrue(result);
        }
Exemplo n.º 10
0
        public void TestLoadTrieAndCheckNumberOfLeafs()
        {
            List <string> words = new List <string> {
                "pygobranchiate",
                "pygofer",
                "pygopagus",
                "pygopod",
                "pygopodine",
                "pygopodous",
                "pygostyle",
                "pygostyled",
                "pygostylous",
                "pyic",
                "pyin",
                "pyins",
                "pyjama",
                "pyjamaed",
                "pyjamas"
            };

            TrieSearch    trie        = new TrieSearch(words);
            List <string> resultWords = trie.GetWordsForPrefix("PY");

            Assert.AreEqual(words.Count, resultWords.Count);

            foreach (var w in resultWords)
            {
                Assert.IsTrue(trie.IsPrefixAWord(w));
            }
        }
Exemplo n.º 11
0
        public void TestHumanLoosingMoveByCompletingWord()
        {
            GameService   gameService = new GameService();
            List <string> words       = new List <string> {
                "pygobranchiate",
                "pygofer",
                "pygopagus",
                "pygopod",
                "pygopodine",
                "pygopodous",
                "pygostyle",
                "pygostyled",
                "pygostylous",
                "pyic",
                "pyin",
                "pyins",
                "pyjama",
                "pyjamaed",
                "pyjamas"
            };

            TrieSearch trie = new TrieSearch(words);

            gameService.setWordsTrie(trie);
            GameState gameState = gameService.processLetter("PYIN", "S");

            Assert.IsTrue(gameState.gameStatus == (int)GameStatusEnum.ComputerWin);
        }
Exemplo n.º 12
0
        public void loadDictionary()
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory + @"Resources\gosthGameDict.txt";

            filePath = filePath.Replace("GhostGame.Api", "GhostGame.Services");
            try
            {
                var lines = File.ReadLines(filePath);
                wordsTree = new TrieSearch(lines);
            }
            catch (Exception e)
            {
                Logger.log(e.Message);
            }
        }
        private List <List <string> > GetSuggestions(string[] dictionary, string searchWord)
        {
            var searchSuggestions = new TrieSearch(dictionary, 3).Build();

            var result = new List <List <string> >();

            var charList = new List <char>();

            foreach (var c in searchWord)
            {
                charList.Add(c);

                var suggestions = searchSuggestions.SearchSuggestion(new string(charList.ToArray()));
                result.Add(suggestions);
            }

            return(result);
        }
Exemplo n.º 14
0
 public void setWordsTrie(TrieSearch trie)
 {
     wordsTree = trie;
 }