public void GetAnagramAsync_DoesUseTheWordList() { //Arrange int factoryUseage = 0; var sources = new IWordList[] { new TestWordList() { Language = "en", WordList = new[] { "ab" } } }; Func <string, IWordGenerator> wordGeneratorFactory = (a) => { factoryUseage++; return(new AbWordGenerator()); }; var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); string word = "ab"; string language = "en"; //Act var actual = objectUnderTest.GetAnagramsAsync(word, language).GetAwaiter().GetResult(); //Assert Assert.AreEqual(1, factoryUseage); Assert.AreEqual("ab", actual.ToArray()[0]); //we put ab in word list and the generator is hard coded also to ab }
public IEnumerable<string> FindWords(IWordList dictionary, string[,] board) { foreach (var seq in FindWordSequences(dictionary, board)) { yield return seq.Word; } }
public static void ClassInitialize(TestContext context) { _testContext = context; _wordDictionary = WordList.Create(); GenerateInputPairs(); }
public MainWindow() { InitializeComponent(); try { // Configure the ABCs of using CardsLibrary DuplexChannelFactory<IWordList> channel = new DuplexChannelFactory<IWordList>(this, "WordFunEndPoint"); // Activate a WordList object words = channel.CreateChannel(); // Register for callbacks callbackId = words.RegisterForCallbacks(); _countdownTimer = new DispatcherTimer(); _countdownTimer.Interval = new TimeSpan(0, 0, 1); _countdownTimer.Tick += new EventHandler(CountdownTimerStep); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { var folder = "Dictionaries"; var fileName = "word*"; string extra = null; string exclusionList = null; var current = Directory.GetCurrentDirectory(); var path = Path.Combine(current, folder); var baseNames = Directory.GetFiles(path, fileName); var sourceFactory = new WordListFileSourceFactory(baseNames, path, extra, exclusionList); source1 = sourceFactory.GetWordList(true)[0]; source1.Load(); source2 = sourceFactory.GetWordList(false)[0]; source2.Load(); string word = "trainers"; //silent,elvis,samples,calipers,trainers, salesman, auctioned,mastering, discounted,reductions,percussion for (int i = 0; i < 1; i++) { RunTests(word); } Console.ReadKey(); }
private PrecomputedImplementation(IWordList wordList) { _wordSetMap = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); int wordSetIndex = 0; Queue <string> queue = new Queue <string>(); while (wordList.Any()) { wordSetIndex++; string firstWord = wordList.First(); wordList = wordList.Without(firstWord); _wordSetMap[firstWord] = wordSetIndex; EnqueueNeighbors(firstWord, queue, ref wordList); while (queue.Any()) { string word = queue.Dequeue(); _wordSetMap[word] = wordSetIndex; EnqueueNeighbors(word, queue, ref wordList); } } }
public void GetAnagrams_DoesSomeUsefulWork() { //Arrange int factoryUseage = 0; IWordList[] sources = new IWordList[] { new TestWordList() { Language = "en" } }; Func <string, IWordGenerator> wordGeneratorFactory = (a) => { factoryUseage++; return(new AbWordGenerator()); }; var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); string word = "ab"; string language = "en"; //Act var actual = objectUnderTest.GetAnagrams(word, language); //Assert Assert.IsNotNull(actual, "there should be some response.."); Assert.AreEqual(1, factoryUseage); }
public IEnumerable <string> FindWords(IWordList dictionary, string[,] board) { foreach (var seq in FindWordSequences(dictionary, board)) { yield return(seq.Word); } }
private void EnqueueNeighbors(string word, Queue <string> queue, ref IWordList wordList) { foreach (var neighbor in EnumerateNeighbors(word, wordList)) { wordList = wordList.Without(neighbor); queue.Enqueue(neighbor); } }
public void Constructor_Throws_WhenInvalidReferenceInSourcesCase2() { //Arrange IWordList[] sources = new IWordList[] { new TestWordList() }; Func <string, IWordGenerator> wordGeneratorFactory = (a) => { return(null); }; //Act //Assert var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); }
public void Constructor_Throws_WhenNullFactory() { //Arrange IWordList[] sources = new IWordList[] { new TestWordList { Language = "en" } }; Func <string, IWordGenerator> wordGeneratorFactory = null; //Act //Assert var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); }
public WordSolver(IWordList wordList) { #region Sanity Check if (wordList == null) { throw new ArgumentNullException("wordList", "No word list provided."); } #endregion _wordList = wordList; _tree = _wordList.Build(); }
public IEnumerable <WordSequence> FindWordSequences(IWordList dictionary, string[,] board) { dict = dictionary; w = board.GetUpperBound(0) + 1; h = board.GetUpperBound(1) + 1; letters = new string[w * h]; places = new Point[w * h]; this.board = board; used = new bool[w, h]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { used[x, y] = false; letters[x + (w * y)] = ""; } } depth = 0; CombinationCount = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { string currentLetter = board[x, y]; if (currentLetter.Contains("/")) { foreach (var letter in currentLetter.Split('/')) { foreach (var seq in FindWordSequences(x, y, letter)) { yield return(seq); } } } else { foreach (var seq in FindWordSequences(x, y, currentLetter)) { yield return(seq); } } } } }
public WordFinderTests() { _wordList = new WordListUserDefined(new List <string> { "elephant", "monkey", "ant", "orangutan", "armadillo", "goat", "giraffe" }); _wordFinder = new WordFinder(_wordList); }
public void EnableResolverThrows_WhenNullResolver() { //Arrange IWordList[] sources = new IWordList[] { new TestWordList() { Language = "en" } }; Func <string, IWordGenerator> wordGeneratorFactory = (a) => { return(null); }; var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); IAnagramResolver resolver = null; //Act //Assert objectUnderTest.EnableResolver(resolver); }
public void GetAnagramsThrows_WhenWordTooLong_Case1() { //Arrange IWordList[] sources = new IWordList[] { new TestWordList() { Language = "en" } }; Func <string, IWordGenerator> wordGeneratorFactory = (a) => { return(null); }; var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); string word = "0123456789AB"; string language = "en"; //Act //Assert objectUnderTest.GetAnagrams(word, language); }
public void GetAnagramsThrows_WhenInvalidLanguage_Case3() { //Arrange IWordList[] sources = new IWordList[] { new TestWordList() { Language = "en" } }; Func <string, IWordGenerator> wordGeneratorFactory = (a) => { return(null); }; var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); string word = "af"; string language = "only en is supported in phase 1"; //Act //Assert objectUnderTest.GetAnagrams(word, language); }
protected IEnumerable <string> EnumerateNeighbors(string word, IWordList dictionary) { for (int i = 0; i < word.Length; i++) { for (char newLetter = 'a'; newLetter <= 'z'; newLetter++) { if (word[i] != newLetter) { string newWord = word.Substring(0, i) + newLetter + word.Substring(i + 1, word.Length - i - 1); if (dictionary.Contains(newWord)) { yield return(newWord); } } } } }
public void SetWordlist(IEnumerable <string> combolist, int position = 0) { if (combolist == null) { throw new ArgumentNullException("Wordlist is null."); } if (combolist.Count() == 0) { throw new ArgumentNullException("Wordlist is null."); } if (position < 0 || position > combolist.Count() - 1) { throw new ArgumentNullException($"Position 0-{combolist.Count() - 1}"); } _position = position; _wordlist = new ComboList(combolist, position); }
public IEnumerable<WordSequence> FindWordSequences(IWordList dictionary, string[,] board) { dict = dictionary; w = board.GetUpperBound(0) + 1; h = board.GetUpperBound(1) + 1; letters = new string[w * h]; places = new Point[w * h]; this.board = board; used = new bool[w, h]; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { used[x, y] = false; letters[x + (w * y)] = ""; } depth = 0; CombinationCount = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { string currentLetter = board[x, y]; if (currentLetter.Contains("/")) { foreach (var letter in currentLetter.Split('/')) foreach (var seq in FindWordSequences(x, y, letter)) yield return seq; } else { foreach (var seq in FindWordSequences(x, y, currentLetter)) yield return seq; } } } }
public void GetAnagramByOptionAsync_Throws() { //Arrange var sources = new IWordList[] { new TestWordList() { Language = "en", WordList = new[] { "ab" } } }; Func <string, IWordGenerator> wordGeneratorFactory = (a) => { return(null); }; var objectUnderTest = new AnagramResolverService(sources, wordGeneratorFactory); var options = new AnagramOptions() { Word = "ab", Language = "en" }; //Act //Assert var actual = objectUnderTest.GetAnagramsAsync(options).GetAwaiter().GetResult(); }
public HangManGame(IWordList wordList) { // DATA allTheWords = wordList; currentWord = new Word(allTheWords.PickRandomWord()); hangingMan = new HangingMan(); incorrectGuesses = new HashSet <string>(); // CONTROLS incorrectGuessesControl = new IncorrectGuessesControl(); currentWordControl = new CurrentWordControl(); currentWordControl.ChangeDisplayedWord(currentWord.GetWord()); nextGuessControl = new ValueView <char>("Enter your next guess: ") { TypeConversionErrorMessage = "Please enter only a single letter." }; hangManControl = new HangManControl(hangingMan); gameOverScreen = new GameOverScreen(); }
public void SetWordlist(IEnumerable <string> userlist, IEnumerable <string> passlist, ComboType type, int position = 0) { if (userlist == null || passlist == null) { throw new ArgumentNullException("Wordlist is null."); } if (userlist.Count() == 0) { throw new ArgumentNullException("Wordlist is null."); } if (passlist.Count() == 0) { throw new ArgumentNullException("Wordlist is null."); } if (position < 0 || position > (userlist.Count() * passlist.Count()) - 1) { throw new ArgumentNullException($"Position 0-{(userlist.Count() * passlist.Count()) - 1}"); } _position = position; _wordlist = new CredentialsList(userlist, passlist, type, position); }
public static void ShouldNotContain(this IWordList wordList, string word) { bool contains = wordList.Contains(word); Assert.IsFalse(contains); }
public WordFinder(IWordList wordList) { _wordList = wordList; }
public static ICatDogGame Create(IWordList wordList) { return(new PrecomputedImplementation(wordList)); }
/// <inheritdoc /> protected override (bool CanContinue, IEnumerable <string> NewlyFoundWordChain) TryGetWordChains( IWordList wordList, string startingWord, string endingWord, IReadOnlyCollection <IWordChain> foundWordChains ) => (CanContinue : false, NewlyFoundWordChain : null);
private NaiveImplementation(IWordList dictionary) { _dictionary = dictionary; }
public static ICatDogGame Create(IWordList dictionary) { return(new NaiveImplementation(dictionary)); }
public void TestInitialize() { _wordList = WordList.Create(); }