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
        }
Exemplo n.º 2
0
		public IEnumerable<string> FindWords(IWordList dictionary, string[,] board)
		{
			foreach (var seq in FindWordSequences(dictionary, board))
			{
				yield return seq.Word;
			}
		}
Exemplo n.º 3
0
        public static void ClassInitialize(TestContext context)
        {
            _testContext    = context;
            _wordDictionary = WordList.Create();

            GenerateInputPairs();
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 8
0
 public IEnumerable <string> FindWords(IWordList dictionary, string[,] board)
 {
     foreach (var seq in FindWordSequences(dictionary, board))
     {
         yield return(seq.Word);
     }
 }
Exemplo n.º 9
0
 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);
     }
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
        public WordSolver(IWordList wordList)
        {
            #region Sanity Check
            if (wordList == null)
            {
                throw new ArgumentNullException("wordList", "No word list provided.");
            }
            #endregion

            _wordList = wordList;
            _tree = _wordList.Build();
        }
Exemplo n.º 13
0
        public WordSolver(IWordList wordList)
        {
            #region Sanity Check
            if (wordList == null)
            {
                throw new ArgumentNullException("wordList", "No word list provided.");
            }
            #endregion

            _wordList = wordList;
            _tree     = _wordList.Build();
        }
Exemplo n.º 14
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public WordFinderTests()
        {
            _wordList = new WordListUserDefined(new List <string>
            {
                "elephant",
                "monkey",
                "ant",
                "orangutan",
                "armadillo",
                "goat",
                "giraffe"
            });

            _wordFinder = new WordFinder(_wordList);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 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);
                 }
             }
         }
     }
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
		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();
        }
Exemplo n.º 23
0
        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();
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        public static void ShouldNotContain(this IWordList wordList, string word)
        {
            bool contains = wordList.Contains(word);

            Assert.IsFalse(contains);
        }
Exemplo n.º 26
0
 public WordFinder(IWordList wordList)
 {
     _wordList = wordList;
 }
Exemplo n.º 27
0
 public static ICatDogGame Create(IWordList wordList)
 {
     return(new PrecomputedImplementation(wordList));
 }
Exemplo n.º 28
0
 /// <inheritdoc />
 protected override (bool CanContinue, IEnumerable <string> NewlyFoundWordChain) TryGetWordChains(
     IWordList wordList, string startingWord, string endingWord,
     IReadOnlyCollection <IWordChain> foundWordChains
     ) => (CanContinue : false, NewlyFoundWordChain : null);
Exemplo n.º 29
0
 private NaiveImplementation(IWordList dictionary)
 {
     _dictionary = dictionary;
 }
Exemplo n.º 30
0
 public static ICatDogGame Create(IWordList dictionary)
 {
     return(new NaiveImplementation(dictionary));
 }
Exemplo n.º 31
0
 public void TestInitialize()
 {
     _wordList = WordList.Create();
 }