Hey guise! Here’s a complete set of test-cases for use in the Complex Numbers (ADT) assignment.

Feel free to clarify and discuss by highlighting and annotating anywhere on the site! πŸ™‚


### We will test with these constructors
### Do not remove

z1 = make_cart(3, 4)
z2 = make_cart(-5, -12)
z3 = make_cart(0, 0)
z4 = make_cart(-5, 2)
z5 = make_cart(2, -5)
z6 = make_polar(5, 2.1)
z7 = make_polar(0, 2)
z8 = make_polar(3.2, -0.3)
z9 = make_cart(1, 1)
set_real(z9, 20)
set_img(z9, -5)

def cmpxisclose(val, real, delta = 10**-3, debug=True):
    if not val or not real:
        return None
    if not debug:
        return sum([ abs(val[i] - real[i]) <= delta for i in range(len(val)) ]) >= len(val) and len(val) == len(real)
    else:
        for i in range(len(val) - 1):
            if not abs(val[i] - real[i]) <= delta:
                print("[ERROR] cmplxIsClose: Value was", val, "- expected", real)
                return False
        return True

def isclose(val, real, delta = 10**-3, debug = True):
    if not val or not real:
        return None
    if not debug:
        return abs(val - real) <= delta
    else:
        if abs(val - real) <= delta:
            return True
        else:
            print("[ERROR] isClose: Value was", val, "- expected", real)
            return False

test = [
    get_real(z1),
    get_img(z2),
    get_real(z9),
    get_img(z9),
    cmpxisclose(add(z1,z2),[-2, -8, True]),
    subtract(z3, z4),
    multiply(z4, z5),
    cmpxisclose(divide(z4,z5),[-0.6896551724137931, -0.7241379310344828, True]) ,
    mod(z1),
    isclose(arg(z1),0.9272952180016122), # 10
    get_mod(z6),
    get_arg(z7),
    cmpxisclose(cart2polar(z2),[13.0, -1.9655874464946583, False]),
    cmpxisclose(polar2cart(z8),[3.0570767652019395, -0.945664661316286, True]),
    cmpxisclose(power(z6,5),[3125, -2.0663706143591725, False]),
    isclose(arg(z4),2.761086276477428),
]

for i in range(len(test)):
    print(i+1, test[i])