public void Load_MixOfWords_FindsOnlyValidWordItemsSeparateByWhitespace() { List <string> words = new List <string>(); WordLoader.Load(" a bc def ghij abcdefghijklmnopqr klmno\tpqrstu\rvwxy\nz ", w => words.Add(w.ToString())); Assert.Equal(new string[] { "A", "BC", "DEF", "GHIJ", "KLMNO", "PQRSTU", "VWXY", "Z" }, words.ToArray()); }
public void Load_EmptyString_DoesNothing() { int count = 0; WordLoader.Load(string.Empty, w => ++ count); Assert.Equal(0, count); }
public void Load_TooLong_DoesNothing() { int count = 0; WordLoader.Load("abcdefghijklmnoqrstuvwxyz", w => ++ count); Assert.Equal(0, count); }
public override List <ProbableMove> Probables() { var Moves = new List <ProbableMove>(); if (!new FileInfo(file).Exists) { return(Moves); } if (CharSet == null || cells == null || weights == null || string.IsNullOrEmpty(file) || (string.IsNullOrEmpty(vowels) && string.IsNullOrEmpty(conso) && string.IsNullOrEmpty(special))) { return(Moves); } if (cells.Length != size * size || weights.Length != size * size) { return(Moves); } string[] All = new string[] { }; string AllPattern = ""; string Movables = (vowels + " " + conso + " " + special); var MovableList = Movables.Replace("(", " ").Replace(")", " ").Replace(",", "").Split(' ').ToList(); MovableList.RemoveAll(x => x.Length == 0); var SpecialList = DistinctList(special.Replace("(", " ").Replace(")", " ").Replace(",", ""), ' '); var SpeicalDict = GetSpecialDict(SpecialList); List <string> EverySyllableOnBoard = GetSyllableList(cells, size, true, false, true); // All = (GetFlatList(EverySyllableOnBoard, ',') + " " + Movables).Replace("(", " ").Replace(")", " ").Replace(",", " ").Replace("|", " ").Split(' '); AllPattern = string.Format("^(?<All>[{0},])*$", GetFlatList2(All)); Dictionary <string, int> AllDict = GetCountDict(All); var WordsDictionary = WordLoader.Load(file); //Large Set of Words var ContextualList = new List <int>() { }; if (CL) { ContextualList = ShortList(WordsDictionary, AllPattern, AllDict); // Probables if (ContextualList.Count > WordsDictionary.Count * Threshlod) { CL = false; } } if (EverySyllableOnBoard.Count > 0) { { var NonCornerSyllables = GetSyllableList(cells, size, false, true, false); var NonCornerPattern = ""; var NonCornerTiles = new string[] { }; var NonCornerDict = new Dictionary <string, int>(); // NonCornerTiles = (GetFlatList2(NonCornerSyllables.ToArray()) + " " + Movables).Replace("(", " ").Replace(")", " ").Replace(",", " ").Replace("|", " ").Split(' '); NonCornerPattern = string.Format("^(?<All>[{0},])*$", GetFlatList2(NonCornerTiles)); NonCornerDict = GetCountDict(NonCornerTiles); // var NonCornerProbables = new List <int>() { }; if (CL) { NonCornerProbables = ShortList(WordsDictionary, ContextualList, NonCornerPattern, NonCornerDict); //Non Corner Probables } else { NonCornerProbables = this.ShortList(WordsDictionary, NonCornerPattern, NonCornerDict); } Moves.AddRange(SyllableExtensions(cells, size, CharSet, id, WordsDictionary, NonCornerProbables, MovableList, SpeicalDict)); } { var CornerSyllables = GetSyllableList(cells, size, false, true, false); var CornerPattern = ""; var CornerTiles = new string[] { }; var CornerDict = new Dictionary <string, int>(); // CornerTiles = (GetFlatList2(CornerSyllables.ToArray()) + " " + Movables).Replace("(", " ").Replace(")", " ").Replace(",", " ").Replace("|", " ").Split(' '); CornerPattern = string.Format("^(?<All>[{0},])*$", GetFlatList2(CornerTiles)); CornerDict = GetCountDict(CornerTiles); // var CornerProbables = new List <int>() { }; if (CL) { CornerProbables = ShortList(WordsDictionary, ContextualList, CornerPattern, CornerDict); //Corner Probables } else { CornerProbables = this.ShortList(WordsDictionary, CornerPattern, CornerDict); } Moves.AddRange(WordExtensions(cells, size, CharSet, id, WordsDictionary, CornerProbables, MovableList, SpeicalDict)); } } else { Moves.AddRange(EmptyExtensions(cells, size, CharSet, star, id, WordsDictionary, ContextualList, MovableList, SpeicalDict)); } WordsDictionary = null; WordsDictionary = null; RefreshScores(Moves, weights, tileWeights, size); return(Moves); }