### Question:
Complex implements Cloneable, Serializable { public void power(final Complex c, final int power) { final double x = c.real; final double y = c.imag; switch (power) { case 0: { real = 1; imag = 0; break; } case 1: { real = x; imag = y; break; } case 2: { real = (x * x) - (y * y); imag = 2 * x * y; break; } case 3: { final double x2 = x * x; final double y2 = y * y; real = x * (x2 - 3*y2); imag = y * (3*x2 - y2); break; } case 4: { final double x2 = x * x; final double y2 = y * y; real = (x2 * x2) - (6 * x2 * y2) + (y2 * y2); imag = 4 * (x * y) * (x2 - y2); break; } case 5: { final double x2 = x * x; final double y2 = y * y; final double x4 = x2 * x2; final double y4 = y2 * y2; final double cr = (x2* y2) * 10; real = x * (x4 - cr + 5*y4); imag = y * (5*x4 - cr + y4); break; } case 6: { final double x2 = x * x; final double y2 = y * y; final double x4 = x2 * x2; final double y4 = y2 * y2; real = (x4 * (x2 - 15*y2) + (15*x2 * y4)) - (y4 * y2); imag = (x * y) * (6 * (x4 + y4) - (20 * x2 * y2)); break; } default: { throw new IllegalArgumentException(String.valueOf(power)); } } } Complex();  Complex(final Complex c);  Complex(final double real, final double imag); void copy(final Complex c); void multiply(final Complex c, final double s); void multiply(final Complex c1, final Complex c2); void divide(final Complex c1, final Complex c2); void add(final Complex c1, final Complex c2); void addMultiply(final Complex c0, final Complex c1, final Complex c2); void power(final Complex c, final int power); @Override Complex clone(); boolean equals(final Complex c); @Override boolean equals(final Object c); @Override int hashCode(); @Override String toString(); public double real; public double imag; }### Answer:
@Test public void testRealPowers() { final double[] bases = {0, 1, 2, 2.5, -2.5}; for (int i=0; i<bases.length; i++) { final double base = bases[i]; final Complex value = new Complex(base, 0); for (int n=0; n<=6; n++) { final String label = String.valueOf(base) + '^' + n; assertEquals(label, pow(base, n), real(power(value, n, label), label), EPS); } } }