(a)
import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;
public class ComplexTest extends TestCase {
private Complex a;
private Complex b;
protected void setUp() {
a = new Complex(1, -1);
b = new Complex(2, 5);
}
}
(b)
public void testComplexEquality()
Complex expected = new Complex(1, -1);
assertEquals(expected, a);
}
public void testComplexAddition() {
Complex expected = new Complex(3, 4);
assertEquals(expected, a.add(b));
}
public void testComplexMultiplication() {
Complex expected = new Complex(1*2 - (-1)*5,1*5 + (-1)*2);
assertEquals(expected, a.multiply(b));
}
(c)
文章来源于领测软件测试网 https://www.ltesting.net/