/** * The test class ComplexTest, to test the Complex class * * @author Phill Conrad, and (insert your name here) * @version lab02 for CS10, Spring 2009 (v2.0) * @see Complex */ public class ComplexTest extends junit.framework.TestCase { // define a static final (a constant) for error tolerance // we'll pass this as the last value of every assertEquals() // call that is done on double values to allow for roundoff error public static final double TOL = 0.00001; public void testNoArgConstructor() { // the no arg constructor should give us zero for // both imaginary and real parts Complex c = new Complex(); assertEquals(0.0,c.getReal(),TOL); assertEquals(0.0,c.getImag(),TOL); } public void testTwoArgConstructor() { // the no arg constructor should give us zero for // both imaginary and real parts Complex c = new Complex( 1.2, -3.4 ); assertEquals( 1.2, c.getReal(), TOL); assertEquals( -3.4, c.getImag(), TOL); } public void testSetters() { // the no arg constructor should give us zero for // both imaginary and real parts Complex c = new Complex(); c.setReal(-3.4); c.setImag(1.2); assertEquals( -3.4, c.getReal(), TOL); assertEquals( 1.2, c.getImag(), TOL); } public void testToString1() { Complex c = new Complex(); assertEquals("0.0 + 0.0i",c.toString()); } public void testToString2() { // the no arg constructor should give us zero for // both imaginary and real parts Complex c = new Complex(1.2, -3.4); assertEquals("1.2 + -3.4i",c.toString()); } public void testToString3() { // the no arg constructor should give us zero for // both imaginary and real parts Complex c = new Complex(2.0, 3.0); assertEquals("2.0 + 3.0i",c.toString()); } }