private void ShowFunction() { list = new List <WordStructure>(); for (int i = 0; i < l.Count; i++) { WordStructure ws = new WordStructure(); ws.str = l[i].word; ws.progress = l[i].num; list.Add(ws); string[] s = l[i].trans.Split(new string[] { "\r\n" }, StringSplitOptions.None); for (int j = 0; j < s.Length; j++) { s[j] = s[j] + "\r\n"; WordStructure w = new WordStructure(); w.str = s[j]; w.progress = -5; list.Add(w); } } int pages = 100; try { pages = (int)list.Count / count; } catch { } LblPages.Text = "/" + pages.ToString(); ShowWord(); }
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(); }
private void ShowWord() { PnlWord.Controls.Clear(); int y = (int)((Height - 95) / 25); int x = (int)((Width - 100) / 350); count = x * y; Label[] l = new Label[count]; if (list.Count == 0) { for (int i = 0; i < count; i++) { WordStructure w = new WordStructure(); w.str = ""; list.Add(w); } } int current = 0; try { int currentpage = (int)(AppInfoHelper.GetCurrentIndex(CbxWordbook.Text) / count) + 1; current = (currentpage - 1) * count; TbxPage.Text = currentpage.ToString(); } catch { } try { for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { int k = i * y + j; l[k] = new Label(); l[k].Name = "label" + k.ToString(); if (current + k < list.Count) { l[k].Text = list[current + k].str; } else { l[k].Text = ""; } Point p = WordPoint(i, j, x); AddLable(l[k], p, l[k].Text, list[current + k].progress); } } } catch { MessageBox.Show("文件已损坏!"); } }
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."); }