def itest_zoom1(): """Test the zoom function with valid values. Zoom should move/reset the 2D plane to a known configuration""" # set up the expected plane xmin = 0 xmax = 10 xstep = 0.5 xlen = 21 ymin = 0 ymax = 10 ystep = 0.5 ylen = 21 # set the constant c c = -1.037 + 0.17j f = jp.julia(c) eplane = [[ f((j * xstep + xmin) + (i * ystep + ymin) * 1j) for i in range(ylen) ] for j in range(xlen)] # create a plane tp = jp.JuliaPlane(100, 200, 21, -100, 0, 21) tp.zoom(xmin, xmax, ymin, ymax) # do the expected and actual planes match? success = tp.plane == eplane message = 'zoom() did not correctly transform the plane to the new coordinate values' assert success, message
def itest_setf1(): """Test that setting the function to a new function updates the plane with the new transformation values""" # set the constant c c = 0.4 - 0.4j # create a plane tp = jp.JuliaPlane(0, 10, 21, 0, 10, 21) # set the function to use c tp.set_f(c) # set up the expected plane xmin = 0 xmax = 10 xstep = 0.5 xlen = 21 ymin = 0 ymax = 10 ystep = 0.5 ylen = 21 f = jp.julia(c) eplane = [[ f((j * xstep + xmin) + (i * ystep + ymin) * 1j) for i in range(ylen) ] for j in range(xlen)] # this line is to force an error to prove the test can fail #eplane[1][1] = 5 # do the expected and actual planes match? success = tp.plane == eplane message = 'set_f() did not correctly transform the plane to double the coordinate values' assert success, message
def test_julia_5(): """Test the julia function to make sure two different function instantiations yield two different results even with the same z value passed to the returned functions""" success = False # make the first julia function f1 = jp.julia(0.2 + 0.2j, 10) # make the second julia function f2 = jp.julia(-0.2 + -0.2j, 2) # call the first julia function again and make sure the output matches the first call # make the results from this call the expected outcome expected = f1(0.7 + 0.7j) actual = f2(0.7 + 0.7j) # how'd we do?? if expected != actual: success = True message = 'Different julia functions constants returned the same value: f1 %d f2 %d' % ( actual, expected) assert success, message
def test_julia_4(): """Test the julia function to make sure a subsequent call to julia does not change the parameters and operation of the first call to julia""" success = False # make the first julia function f1 = jp.julia(0.2 + 0.2j, 10) # make the results from this call the expected outcome expected = f1(0.7 + 0.7j) # make the second julia function f2 = jp.julia(-0.2 + -0.2j, 2) # call the first julia function again and make sure the output matches the first call actual = f1(0.7 + 0.7j) # how'd we do?? if expected == actual: success = True message = 'Julia function internals changed between indpendent instatiations: actual %d expected %d' % ( actual, expected) assert success, message
def _do_julia(c, z, loop_max=100): """This private function is for testing julia only""" f = jp.julia(c, loop_max) return f(z)