示例#1
0
        public void DontChangeWords_ByDefault()
        {
            var words = new[] { "one", "two", "three" };

            reader.ReadWords().Returns(words);

            provider.GetWords().ShouldBeEquivalentTo(words);
        }
示例#2
0
        public Result <IEnumerable <Tag> > CreateTags(int maxCount = 100)
        {
            var result = provider.GetWords();

            return(!result.IsSuccess ?
                   Result.Fail <IEnumerable <Tag> >(result.Error) :
                   Result.Ok(CreateTags(maxCount, result.Value)));
        }
示例#3
0
        public List <string> GetAllWordChains(string startWord, string endWord)
        {
            _wordBank = _provider.GetWords("wordlist.txt", startWord.Length);
            List <string> currentChains;

            currentChains = CheckForWordChains(startWord, endWord);

            while (FoundNewChains == true && _completeChains.Count == 0)
            {
                List <string> newChains = new List <string>();
                foreach (string chain in currentChains)
                {
                    newChains.AddRange(CheckForWordChains(chain, endWord));
                }
                currentChains = newChains;
            }
            return(_completeChains);
        }
示例#4
0
        public Dictionary <string, string> RetrieveAnagrams(string dictionaryLocation)
        {
            List <string> lines      = _provider.GetWords(dictionaryLocation);
            List <string> outputList = new List <string>();


            foreach (string line in lines)
            {
                var sorted = _sorter.SortWord(line);
                if (outputDict.ContainsKey(sorted))
                {
                    outputDict[sorted] = $"{outputDict[sorted]} {line}";
                }
                else
                {
                    outputDict.Add(sorted, line);
                }
            }

            return(outputDict);
        }
        public async Task <IEnumerable <WordDefinition> > GetWords(string wordString, string wordType = "")
        {
            _logger.LogInformation($"Getting words based on word string: {wordString}");
            wordString = wordString.Trim().ToLower().RemoveStressMarks();
            var words = await GetWordFromCache(wordString, wordType);


            if (words.Count() == 0)
            {
                _logger.LogInformation($"Cache miss for word: {wordString}");
                try
                {
                    _logger.LogInformation($"Get words from wordprovider for: {wordString}");
                    var providerWordList = await _wordProvider.GetWords(wordString);

                    if (providerWordList != null && providerWordList.Count() > 0)
                    {
                        words = providerWordList.ToList();
                        _logger.LogInformation($"Retrieved {words.Count()} words from wordprovider for: {wordString}");
                        SaveWord(words);
                    }
                    else
                    {
                        _logger.LogInformation($"No words retrieved from wordprovider for: {wordString}");
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                    return(null);
                }
            }
            else
            {
                _logger.LogInformation($"Cache hit for word: {wordString}");
            }


            return(words);
        }