def test_error_tracker(): delta_x = 0.01 * np.ones(100) exact = lambda t: np.linspace(0, 1, 100) + t params = Data() params.error_norm = 1 params.plotter = Data() params.plotter.never_plot = True e1 = ErrorTracker(Mesh(delta_x), exact, params) params.error_norm = 2 e2 = ErrorTracker(Mesh(delta_x), exact, params) for i in range(1, 10): # the exact result is x + i e1.update(e1.mesh.x + 0.9 * i, float(i), 1.0) # in any norm the error should be 0.i assert(abs(e1.error[i] - i * 0.1) <= 1e-9) new_val = exact(i) new_val[0] = 0 # the difference e2.update(new_val, float(i), 1.0) # L2 norm of the error should be 0.(i + 1) assert(abs(e2.error[i] - (i * 0.01)) <= 1e-9)