- 論壇徽章:
- 0
|
需求:反轉(zhuǎn)一個(gè)句子
我可能會(huì)寫(xiě)出以下的測(cè)試——寫(xiě)一個(gè)測(cè)試,然后寫(xiě)代碼讓測(cè)試通過(guò),然后再寫(xiě)下一個(gè)測(cè)試。
自己看吧。- public class StringReverseTest {
- # Test 1
- public void testShouldSplitSentenceIntoWords(){
- StringReverser sr=new StringReverser();
- String str = "This is a sentence";
- Assert.assertEquals(4, sr.split(str).size());
- Assert.assertEquals("sentence", sr.split(str).get(0));
- Assert.assertEquals("a", sr.split(str).get(1));
- Assert.assertEquals("is", sr.split(str).get(2));
- Assert.assertEquals("This", sr.split(str).get(3));
- }
- # Test 2
- public void testShouldReverseSentence(){
- StringReverser sr=new StringReverser();
- String str = "Tdd is a software devolopment technology";
- Assert.assertEquals("technology devolopment software a is Tdd",sr.reverse(str));
- }
- # Test 3
- public void testShouldAlwaysReverseSentences(){
- StringReverser sr=new StringReverser();
- String str = "This is Yet Another sentence";
- Assert.assertEquals("sentence Another Yet is This",sr.reverse(str));
- }
- }
復(fù)制代碼 原文http://www.javaeye.com/topic/124959 |
|