public void LetterALongestWordsTest() { var letterA = DictionaryLetter.InitializeDictionaryLetter('a', new MockDictionary()); var longestWords = letterA.GetLongestWords(); Assert.AreEqual(2, longestWords.Count); Assert.AreEqual("abbreviations", longestWords.First()); Assert.AreEqual("abductions", longestWords.Last()); }
public void LetterSWordsInWordListTest() { var letterS = DictionaryLetter.InitializeDictionaryLetter('s', new MockDictionary()); string[] letterSWords = new string[] { "stammer", "stamp", "stance", "standard", "standstill" }; foreach (string s in letterSWords) { Assert.IsTrue(letterS.WordsBeginningWith.Contains(s)); } }
public void LetterAWordsInWordListTest() { var letterA = DictionaryLetter.InitializeDictionaryLetter('a', new MockDictionary()); string[] letterAWords = new string[] { "abbreviations", "abdicates", "abductions", "abductors", "abilities" }; foreach (string s in letterAWords) { Assert.IsTrue(letterA.WordsBeginningWith.Contains(s)); } }
public void WordListLengthAndPropertyEqualTest(char letter) { var letterWhat = DictionaryLetter.InitializeDictionaryLetter(letter, new MockDictionary()); Assert.AreEqual(letterWhat.NumberWordsBeginningWith, letterWhat.WordsBeginningWith.Count); }
public void AverageCharacterCountTest(char letter, int avgCount) { var letterWhat = DictionaryLetter.InitializeDictionaryLetter(letter, new MockDictionary()); Assert.AreEqual(avgCount, letterWhat.AverageCharacterCount); }
public void NumberEndingWithLetterTest(char letter, int numberEnding) { var letterWhat = DictionaryLetter.InitializeDictionaryLetter(letter, new MockDictionary()); Assert.AreEqual(numberEnding, letterWhat.NumberWordsEndingWith); }
public void AverageCharacterCountEmptyDictionaryTest(char alphabetLetter) { var eachLetter = DictionaryLetter.InitializeDictionaryLetter(alphabetLetter, new MockDictionary(new string[0])); Assert.AreEqual(0, eachLetter.AverageCharacterCount); }
public async Task <int> AddWordsToDictionary(Stream wordStream) { int wordsAdded = 0; // Dictionary corresponding to the to-be-added wordlist ActiveDictionary addDictionary; try { addDictionary = Loader.LoadDictionary(wordStream); } catch (FileLoadException) { // Empty, Abort return(0); } // Dictionary corresponding to the in-database wordlist var dbDictionary = context.GetWordDictionaryForContext(); var lettersToUpdate = addDictionary.GetAllDictionaryLetters().Select(dl => dl.Letter).ToList(); // Get the actual entities from the DB List <Letter> letters = await context.Letters.Where(letter => lettersToUpdate.Contains(letter.Character)) .OrderBy(letter => letter.Character) .ToListAsync(); try { foreach (var letter in letters) { var addTheseWords = addDictionary.GetDictionaryWordsStartingWith(letter.Character) .Select(word => new Word() { TheWord = word, Letter = letter }); wordsAdded += context.AddWordEntities(addTheseWords); } } finally { await context.SaveChangesAsync(); } // Changes must be saved prior to getting updated states. fml -.- try { foreach (var letter in letters) { // Update Letter Statistics var updatedLetterStats = DictionaryLetter.InitializeDictionaryLetter(letter.Character, dbDictionary); letter.AverageCharacters = updatedLetterStats.AverageCharacterCount; letter.CountBeginningWith = updatedLetterStats.NumberWordsBeginningWith; letter.CountEndingWith = updatedLetterStats.NumberWordsEndingWith; context.Letters.Update(letter); } } finally { await context.SaveChangesAsync(); } return(wordsAdded); }