Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("-------------------------------------");
            Console.WriteLine("| Vocable Parser                    |");
            Console.WriteLine("-------------------------------------");

            // read the word structure.
            Console.Write("> Enter word structure: ");
            var strStructure = Console.ReadLine().ToUpper();

            // create the word structure.
            WordStructure structure = WordStructure.Parse(strStructure);

            // get a list of unique characters used in the word structure.
            var uniqueChars = strStructure
                              .Replace(ParserSymbols.OPTIONAL_START.ToString(), string.Empty)
                              .Replace(ParserSymbols.OPTIONAL_END.ToString(), string.Empty);

            uniqueChars = new string(uniqueChars.Distinct().ToArray());

            // loop through the list of unique characters and prompt the
            // user to enter its word list.
            foreach (char letter in uniqueChars)
            {
                Console.Write(String.Format("> Enter values for {0}: ", letter));
                var         ipaUnicodes = Console.ReadLine();
                List <Word> baseWords   = new List <Word>();
                foreach (string unicode in ipaUnicodes.Split(','))
                {
                    Sound sound = new Sound(unicode);
                    Word  word  = new Word(sound);
                    baseWords.Add(word);
                }

                structure.FillComponents(letter, baseWords.ToArray());
            }

            // build the word list.
            var currentTime = DateTime.Now.TimeOfDay;
            var words       = structure.BuildWords();
            var elapsedTime = DateTime.Now.TimeOfDay.Subtract(currentTime);

            // print stats about the generated results.
            Console.WriteLine();
            Console.WriteLine("-------------------------------------");
            Console.WriteLine("| Generated Words (in {0:0.0000} secs)  |", elapsedTime.TotalSeconds);
            Console.WriteLine("-------------------------------------");
            Console.WriteLine("| Total Words: {0}", words.Count());
            Console.WriteLine();

            // print the results.
            var sortedWords = words.OrderBy(w => w.Sounds.Count).ThenBy(w => w);

            ConsoleUtils.WriteListWithLineNumbers(sortedWords);

            // prevent app from closing.
            Console.ReadLine();
        }
        public void WordStructure_OnlyOptionalComponents_ValidResult()
        {
            // arrange
            string[]      expectedResults = { "ab", "a", "b" };
            WordStructure structure       = WordStructure.Parse("(V)(C)");

            structure.FillComponents('V', _oneVowelWord);
            structure.FillComponents('C', _oneConsonantWord);
            // act
            var results       = structure.BuildWords();
            var simpleResults = WordsAsStrings(results);

            // assert
            Assert.IsTrue(simpleResults.All(expectedResults.AsEnumerable().Contains), "Unexpected results using only optional components.");
            Assert.IsTrue(results.Count() == expectedResults.Count(), "Count of result does not match expected.");
        }
        public void WordStructure_ConstantAndOptionalComponents_ValidResult()
        {
            // arrange
            string[]      expectedResults = { "ab", "ac", "ib", "ic", "aba", "abi", "aca", "aci", "iba", "ibi", "ica", "ici" };
            WordStructure structure       = WordStructure.Parse("VC(V)");

            structure.FillComponents('V', _twoVowelWords);
            structure.FillComponents('C', _twoConsonantWords);
            // act
            var results       = structure.BuildWords();
            var simpleResults = WordsAsStrings(results);

            // assert
            Assert.IsTrue(simpleResults.All(expectedResults.AsEnumerable().Contains), "Unexpected results using constant and optional components.");
            Assert.IsTrue(results.Count() == expectedResults.Count(), "Count of result does not match expected.");
        }