public void Initialises_chain_correctly() { var sut = new WordChain("word", "anotherWord"); Assert.AreEqual("anotherWord", sut.EndWord); Assert.AreEqual(new[] { "word", "anotherWord" }, sut.Path); }
public void ShouldGenerateAWordChain_GivenStartingAndEndingWord(string startingWord, string endingWord, string[] expectedWordChain) { var wordChain = new WordChain(_dictionary, startingWord, endingWord); var actualWordChain = wordChain.Create(1); Assert.Equal(expectedWordChain.ToList().ToString(), actualWordChain.ToString()); }
public void Initialises_chain_correctly_if_start_word_is_end_word() { var sut = new WordChain("word", "word"); Assert.AreEqual("word", sut.EndWord); Assert.AreEqual(new[] { "word" }, sut.Path); }
public void Adds_another_word_correctly_if_word_is_already_end_word() { var sut = new WordChain("word", "anotherWord"); var result = new WordChain(sut, "anotherWord"); Assert.AreEqual("anotherWord", result.EndWord); Assert.AreEqual(new[] { "word", "anotherWord" }, result.Path); }
public void Adds_another_word_correctly() { var sut = new WordChain("word", "anotherWord"); var result = new WordChain(sut, "finalWord"); Assert.AreEqual("finalWord", result.EndWord); Assert.AreEqual(new[] { "word", "anotherWord", "finalWord" }, result.Path); }
public void Test1() { var words = new string[] { "a", "and", "an", "bear" }; var result = WordChain.LongestChain(words.ToList()); result.ShouldBe(3); }
public void Words_contains_the_same_elements_as_the_given_list() { var words = TestData.CreateListOfWordsEnumerable(20).ToList(); var sut = WordChain.New(words, TimeSpan.Zero); Assert.Equal(words.Count, sut.Words.Count()); Assert.All(sut.Words, word => Assert.Contains(word, words)); }
public void Test3() { var words = new string[] { "a", "ba", "aba", "abac", "agacd" }; var result = WordChain.LongestChain(words.ToList()); result.ShouldBe(4); }
public void Test4() { var words = new string[] { "9", "a", "zxb", "ba", "bca", "bda", "bdca", "zxbe", "azxbe", "azxpbe" }; var result = WordChain.LongestChain(words.ToList()); result.ShouldBe(4); }
public void New_produces_an_object_that_is_of_type_IWordChain() => Xssert .TheActualType(actualTypeSelector: () => WordChain.New( words: TestData.CreateListOfWordsEnumerable(2), duration: TimeSpan.Zero ) ) .IsDerivedFromTheExpectedType <IWordChain>() ;
public void Throws_ArgumentOutOfRangeException_when_words_parameter_holds_less_than_two_words(int amountOfWords) => Xssert.ThrowsArgumentOutOfRangeException( testCode: () => { var words = TestData.CreateListOfWordsEnumerable(amountOfWords); WordChain.New(words: words, duration: TimeSpan.Zero); }, expectedParameterName: "words", expectedMessageContains: $"The parameter 'words' should at least contain 2 words, in stead of the provided amount of '{amountOfWords}' words." ) ;
//“生成”按钮 单击事件 private void button1_Click(object sender, EventArgs e) { string textInput = ""; if (tabPage.SelectedIndex == 0) { string filename = Directory.GetCurrentDirectory() + "\\" + textBox2.Text; if (File.Exists(filename)) { textInput = File.ReadAllText(filename); } } else { textInput = textBox1.Text; } if (textInput.Length == 0) { textBox5.Text = "ERROR : NO INPUT !"; return; } //确定char_h char_t if (!b_h) { char_h = '#'; } if (!b_t) { char_t = '#'; } //调用ConsoleApp1项目内对应接口实现 textOutput = ""; char c_wc = b_w ? 'w' : 'c'; coreBuild core = new coreBuild(); WordChain wc = core.get_chainByLine(textInput, char_h, char_t, b_r, c_wc); foreach (Word word in wc.GetWordChain()) { textOutput += word.Get_allWord(); } //输出指结果框 textBox5.Text = textOutput; }
public int gen_chain_char(string[] words, int len, string[] result, char head, char tail, bool enable_loop) { if (!((head <= 'z' && head >= 'a') || (head == '\0'))) { throw new Exception("首字母不符合规范"); } if (!((tail <= 'z' && tail >= 'a') || (tail == '\0'))) { throw new Exception("尾字母不符合规范"); } if (head == '\0') { head = '#'; } if (tail == '\0') { tail = '#'; } Word.setWeightChosen('c'); if (!enable_loop) //没有-r的情况 { ReadFile readFile = new ReadFile(); readFile.buildWordList(words); readFile.run2(); Topo tp = new Topo(); tp.run(head, tail); return(tp.getLongesChain().getWeight()); } else //有 { ReadFile readFile = new ReadFile(); readFile.buildWordList(words); WordChainProcessor wcp = new WordChainProcessor(ReadFile.GetWordChainUnDo(), 'c', head, tail); WordChain wchain = wcp.getResultChain(); return(wchain.getWeight()); } throw new NotImplementedException(); }
public WordChain build_chain_char(string[] words, int len, string[] result, char head, char tail, bool enable_loop) { Word.setWeightChosen('c'); if (!enable_loop) //没有-r的情况 { ReadFile readFile = new ReadFile(); readFile.buildWordList(words); readFile.run2(); Topo tp = new Topo(); tp.run(head, tail); return(tp.getLongesChain()); } else //有 { ReadFile readFile = new ReadFile(); readFile.buildWordList(words); WordChainProcessor wcp = new WordChainProcessor(ReadFile.GetWordChainUnDo(), 'c', head, tail); WordChain wchain = wcp.getResultChain(); return(wchain); } throw new NotImplementedException(); }
public static IEnumerable <object[]> Duration_is_calulcated_accordingly_for_a_given_IWordChain_collection_TestData() => new List <object[]> { new object[] { new List <IWordChain> { WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(1)) }, TimeSpan.FromSeconds(1) }, new object[] { new List <IWordChain> { WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(1)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(5)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromMinutes(1)) }, new TimeSpan(hours: 0, minutes: 1, seconds: 6), }, new object[] { new List <IWordChain> { WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromMilliseconds(505)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(5)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromMinutes(3)) }, new TimeSpan(hours: 0, minutes: 3, seconds: 5).Add(TimeSpan.FromMilliseconds(505)), } } ;
public static IEnumerable <object[]> IWordChain_collections_are_equivalent_as_those_that_where_passed_TestData() => new List <object[]> { new object[] { new List <IWordChain> { WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(1)) }, 1 }, new object[] { new List <IWordChain> { WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(1)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(5)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromMinutes(1)) }, 3 }, new object[] { new List <IWordChain> { WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromMilliseconds(505)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromSeconds(5)), WordChain.New(TestData.CreateListOfWordsEnumerable(10), TimeSpan.FromMinutes(3)) }, 3 } } ;
public void Throws_ArgumentNullException_when_words_parameter_is_null() => Xssert.ThrowsArgumentNullException( testCode: () => WordChain.New(words: null, duration: TimeSpan.Zero), expectedParameterName: "words" ) ;
public void EndingWord_is_the_same_as_the_last_word_in_the_given_list() => Assert.Equal("word20", WordChain.New(TestData.CreateListOfWordsEnumerable(20), TimeSpan.Zero).EndingWord);
public void Length_reflects_the_number_of_words_in_the_chain(int amountOfWords) => Assert.Equal(amountOfWords, WordChain.New(TestData.CreateListOfWordsEnumerable(amountOfWords), TimeSpan.Zero).Length);