參考 http://www.cnblogs.com/rocedu/p/6371315.html#SECUNITTESThtml
參考http://www.cnblogs.com/rocedu/p/6736847.htmljava
提交最後三個測試用例都經過的截圖,截圖上要有畫圖加水印,輸入本身的學號。git
正常狀況:
設計模式
錯誤狀況:
app
邊界狀況:
ide
最終結果:
函數
參考 積極主動敲代碼,使用JUnit學習Java (http://www.cnblogs.com/rocedu/p/4837092.html)單元測試
參考http://www.cnblogs.com/rocedu/p/6736847.html學習
以 TDD的方式研究學習StringBuffer,提交你的單元測試用例和測試經過的截圖,截圖要加上學號水印。測試
安裝JUnitGenerator V2.0
public class StringBufferDemo { public StringBuffer setBuffer() { StringBuffer buffer = new StringBuffer(); buffer.append('S'); buffer.append("tringBuffer"); System.out.println(buffer.charAt(1)); System.out.println(buffer.length()); System.out.println(buffer.capacity()); System.out.println(buffer.indexOf("tring")); System.out.println(buffer.toString()); return buffer; } }
import junit.framework.TestCase; import org.junit.Test; public class StringBufferDemoTest extends TestCase { StringBuffer buffer1 = new StringBuffer("StringBuffer"); StringBuffer buffer2 = new StringBuffer("StringBufferStringBuffer"); StringBuffer buffer3 = new StringBuffer("StringBufferStringBufferStringBuffer"); @Test public void testcharAt() { assertEquals('S',buffer1.charAt(0)); assertEquals('r',buffer1.charAt(11)); } @Test public void testlength(){ assertEquals(12,buffer1.length()); assertEquals(24,buffer2.length()); assertEquals(36,buffer3.length()); } @Test public void testcapacity(){ assertEquals(28,buffer1.capacity()); assertEquals(40,buffer2.capacity()); assertEquals(52,buffer3.capacity()); } @Test public void testToString(){ assertEquals("StringBuffer",buffer1.toString()); assertEquals("StringBufferStringBuffer",buffer2.toString()); } @Test public void testIndexOf(){ assertEquals(0,buffer1.indexOf("Str")); assertEquals(5,buffer1.indexOf("gBu")); } }
參考http://www.cnblogs.com/rocedu/p/6736847.html
對設計模式示例進行擴充,體會OCP原則和DIP原則的應用,初步理解設計模式
用本身的學號%6進行取餘運算,根據結果進行代碼擴充:
0: 讓系統支持Byte類,並在MyDoc類中添加測試代碼代表添加正確,提交測試代碼和運行結的截圖,加上學號水印
1: 讓系統支持Short類,並在MyDoc類中添加測試代碼代表添加正確,提交測試代碼和運行結的截圖,加上學號水印
2: 讓系統支持Boolean類,並在MyDoc類中添加測試代碼代表添加正確,提交測試代碼和運行結的截圖,加上學號水印
3: 讓系統支持Long類,並在MyDoc類中添加測試代碼代表添加正確,提交測試代碼和運行結的截圖,加上學號水印
4: 讓系統支持Float類,並在MyDoc類中添加測試代碼代表添加正確,提交測試代碼和運行結的截圖,加上學號水印
5: 讓系統支持Double類,並在MyDoc類中添加測試代碼代表添加正確,提交測試代碼和運行結的截圖,加上學號水印
// Server Classes abstract class Data { abstract public void DisplayValue(); } class Integer extends Data { int value; Integer() { value=300; } public void DisplayValue(){ System.out.println (value); } } class Float extends Data { float value; Float() { value=2.688F; } public void DisplayValue(){ System.out.println (value); } } // Pattern Classes abstract class Factory { abstract public Data CreateDataObject(); } class IntFactory extends Factory { public Data CreateDataObject(){ return new Integer(); } } class FloatFactory extends Factory { public Data CreateDataObject(){ return new Float(); } } class Document { //Client classes Data pd; Document(Factory pf){ pd = pf.CreateDataObject(); } public void DisplayData(){ pd.DisplayValue(); } } //Test class public class MyDoc { static Document d,f; public static void main(String[] args) { d = new Document(new IntFactory()); d.DisplayData(); f = new Document(new FloatFactory()); f.DisplayData(); } }
提交:單元測試代碼和運行成功截圖及碼雲上代碼連接,截圖要加上學號水印
參考http://www.cnblogs.com/rocedu/p/6736847.html
任務:以TDD的方式開發一個複數類Complex,要求以下:
// 定義屬性並生成getter,setter
double RealPart;
double ImagePart;
// 定義構造函數
public Complex()
public Complex(double R,double I)
//Override Object
public boolean equals(Object obj)
public String toString()
// 定義公有方法:加減乘除
Complex ComplexAdd(Complex a)
Complex ComplexSub(Complex a)
Complex ComplexMulti(Complex a)
Complex ComplexDiv(Complex a)
public class Complex { //定義屬性並生成getter,setter double RealPart; double ImagePart; public double getterRealPart() { return RealPart; } public double getterImagePart() { return ImagePart; } public void setter(double r, double i) { RealPart = r; ImagePart = i; } //定義構造函數 public Complex(){ } public Complex(double r, double i) { RealPart = r; ImagePart = i; } //Override Object public boolean equals(Object obj){ if(this == obj){ return true; } else { return false; } } public String toString() { String result = new String(); if (ImagePart > 0) result = RealPart+"+"+ImagePart+"i"; if (ImagePart == 0) result = RealPart+""; if (ImagePart < 0) result = RealPart+"-"+ImagePart*(-1)+"i"; return result; } //定義公有方法:加減乘除 public Complex ComplexAdd(Complex obj) { return new Complex ((getterRealPart()+obj.getterRealPart()),(getterImagePart()+obj.getterImagePart())); } public Complex ComplexSub(Complex obj) { return new Complex ((getterRealPart()-obj.getterRealPart()),(getterImagePart()-obj.getterImagePart())); } public Complex ComplexMulti(Complex obj) { return new Complex ((getterRealPart()*obj.getterRealPart()-getterImagePart()*obj.getterImagePart()),(getterRealPart()*obj.getterImagePart()+getterImagePart()*obj.getterRealPart())); } public Complex ComplexDiv(Complex obj){ double div = Math.sqrt(obj.RealPart*obj.RealPart)+Math.sqrt(obj.ImagePart*obj.ImagePart); return new Complex(((RealPart*obj.RealPart+ImagePart*obj.ImagePart)/div),((ImagePart*obj.RealPart-RealPart*obj.ImagePart)/div)); } }
import junit.framework.TestCase; import org.junit.Test; public class ComplexTest extends TestCase { Complex c1 = new Complex(2,4); Complex c2 = new Complex(-1,1); @Test public void testComplexAdd(){ assertEquals("1.0+5.0i",c1.ComplexAdd(c2)+""); } @Test public void testComplexSub(){ assertEquals("3.0+3.0i",c1.ComplexSub(c2)+""); } @Test public void testComplexMulti(){ assertEquals("-6.0-2.0i",c1.ComplexMulti(c2)+""); } @Test public void testComplexDiv(){ assertEquals("1.0-3.0i",c1.ComplexDiv(c2)+""); } }
使用WhiteStarUML對實驗二中的代碼進行建模,發類圖的截圖,加上學號水印。
參考http://www.cnblogs.com/rocedu/p/6736847.html
類圖中只少兩個類。
類圖:
junit
使用org.junit
不存在,junit
部分顯示紅色File
——Project Struct……
——Libraies
——點擊加號
——Java
——找到 IDEA 安裝路徑下的junit-4.12
——點擊OK
步驟 | 耗時 | 百分比 |
---|---|---|
需求分析 | 20min | 10% |
設計 | 40min | 20% |
代碼實現 | 70min | 35% |
測試 | 30min | 15% |
分析總結 | 40min | 20% |