标签:
使用TDD的方式设计实现复数类 Complex 自己请教张薇用这个东西 所以直接用了梓靖的代码 重新完成她的实验。
import org.junit.Test; public class ComplexNumberTest { @Test public void TestFunction1() { ComplexNumber complexnumber = new ComplexNumber(3, 5); ; assert complexnumber.mdRealPart == 3 : "ComplexNumber(double r,double I)构造函数有错误"; assert complexnumber.mdImaginPart == 5 : "ComplexNumber(double r,double I)构造函数有错误"; }
@Test
public void TestFunction2() {
ComplexNumber complexnumber = new ComplexNumber();
assert complexnumber.m_dImaginPart == 0 : "ComplexNumber()构造函数有错误";
assert complexnumber.m_dRealPart == 0 : "ComplexNumber()构造函数有错误";
}
@Test
public void TestSetWay() {
ComplexNumber complexnumber = new ComplexNumber();
complexnumber.SetRealPart(1);
complexnumber.SetImaginaryPart(1);
assert complexnumber.m_dRealPart == 1 : "SetRealPart方法有错误";
assert complexnumber.m_dImaginPart == 1 : "SetImaginaryPart方法有错误";
}
@Test
public void TestgetWay() {
ComplexNumber complexnumber = new ComplexNumber();
complexnumber.SetRealPart(3);
complexnumber.SetImaginaryPart(5);
assert complexnumber.GetRealPart() == 3 : "GetRealPart方法有错误";
assert complexnumber.GetImaginaryPart() == 5 : "GetImaginaryPart方法有错误";
}
@Test
public void TestStringWay() {
ComplexNumber complexnumber = new ComplexNumber(3,5);
assert complexnumber.toString()=="3.0+5.0i":"toString方法有错误";
}
@Test
public void TestAddWay1() {
ComplexNumber complexnumber1 = new ComplexNumber(1,1);
ComplexNumber complexnumber2 = new ComplexNumber(2,2);
ComplexNumber complexnumber3=complexnumber1.ComplexAdd1(complexnumber2);
assert complexnumber3.m_dRealPart == 3 : "ComplexAdd方法有错误";
assert complexnumber3.m_dImaginPart == 3 : "ComplexAdd方法有错误";
}
@Test
public void TestAddWay2() {
ComplexNumber complexnumber1 = new ComplexNumber(1,1);
ComplexNumber complexnumber2=complexnumber1.ComplexAdd2(2);
assert complexnumber2.m_dRealPart == 3 : "ComplexAdd方法有错误";
assert complexnumber2.m_dImaginPart == 1 : "ComplexAdd方法有错误";
}
@Test
public void TestMinusWay1() {
ComplexNumber complexnumber1 = new ComplexNumber(1,1);
ComplexNumber complexnumber2 = new ComplexNumber(2,2);
ComplexNumber complexnumber3=complexnumber2.ComplexMinus1(complexnumber1);
assert complexnumber3.m_dRealPart == 1 : "ComplexMinus方法有错误";
assert complexnumber3.m_dImaginPart == 1 : "ComplexMinus方法有错误";
}
@Test
public void TestMinusWay2() {
ComplexNumber complexnumber1 = new ComplexNumber(5,1);
ComplexNumber complexnumber2=complexnumber1.ComplexMinus2(1);
assert complexnumber2.m_dRealPart == 4 : "ComplexMinus方法有错误";
assert complexnumber2.m_dImaginPart == 1 : "ComplexMinus方法有错误";
}
@Test
public void TestMultiWay1() {
ComplexNumber complexnumber1 = new ComplexNumber(3,3);
ComplexNumber complexnumber2 = new ComplexNumber(3,5);
ComplexNumber complexnumber3=complexnumber1.ComplexMulti1(complexnumber2);
assert complexnumber3.m_dRealPart == -6 : "ComplexMinus方法有错误";
assert complexnumber3.m_dImaginPart == 24 : "ComplexMinus方法有错误";
}
@Test
public void TestMultiWay2() {
ComplexNumber complexnumber1 = new ComplexNumber(3,3);
ComplexNumber complexnumber2=complexnumber1.ComplexMulti2(2);
assert complexnumber2.m_dRealPart == 6 : "ComplexMinus方法有错误";
assert complexnumber2.m_dImaginPart == 6 : "ComplexMinus方法有错误";
}
自己还是没学到很多.得加油了。
标签:
原文地址:http://www.cnblogs.com/dj20145339/p/5402289.html