Commit 9eef9328 authored by jordan.dalby's avatar jordan.dalby

+ ComplexTest commit

parent 07fc3d3f
......@@ -48,4 +48,26 @@ public class Complex
return c;
}
@Override
public String toString()
{
String s = "";
if (realPart != 0)
s+=String.valueOf(this.realPart);
if (realPart != 0 && imaginaryPart != 0)
{
if (imaginaryPart < 0)
s += " - ";
else
s += " + ";
}
if (imaginaryPart != 0)
{
s+="j" + String.valueOf(Math.abs(this.imaginaryPart));
}
return s;
}
}
......@@ -48,7 +48,7 @@ class ComplexTest {
void testToString() {
/* toString() should return a string like 1.2 + j3.4 where 1.2 is the real part
* and 3.4 the imaginary part.
*
*/
Complex a = new Complex(1.2, 3.4);
assertEquals("1.2 + j3.4", a.toString());
Complex b = new Complex(1.2, 0.0);
......@@ -56,6 +56,6 @@ class ComplexTest {
Complex c = new Complex(0.0, 9.3);
assertEquals("j9.3", c.toString());
Complex d = new Complex(1.2, -3.4);
assertEquals("1.2 - j3.4", d.toString());*/
assertEquals("1.2 - j3.4", d.toString());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment