import static org.junit.Assert.*; import java.util.Random; import org.junit.Test; public class ComplexTest { Random r = new Random(); private int random() { return r.nextInt(500) - 250; } @Test public void testAdd() { for (int i = 0; i < 100; i++) { // Generate random numbers and test addition with them int a1 = random(), b1 = random(), a2 = random(), b2 = random(); Complex n1 = new Complex(a1, b1); Complex n2 = new Complex(a2, b2); Complex n3 = n1.add(n2); // The first two assertions check to see that the original Complex // objects aren't modified (hence, a new object is created). The // last assertion checks to make sure the result is as expected. assertTrue(n1.getA() == a1 && n1.getB() == b1); assertTrue(n2.getA() == a2 && n2.getB() == b2); assertTrue(n3.getA() == a1 + a2 && n3.getB() == b1 + b2); } } @Test public void testSub() { fail("Not yet implemented"); } @Test public void testMul() { fail("Not yet implemented"); } @Test public void testMagnitude() { fail("Not yet implemented"); } }