def test_int_ensures_the_bcf_func_is_called_corrrectly(): # Arrange mock = MagicMock(return_value=[0, 0]) # Act pde_solve(base_L, base_T, base_u_I, base_mx, base_mt, bcf=mock) # Assert assert mock.call_count == base_mt
def test_integration_ensures_that_u_I_is_called_multiple_times(): # Arrange mock = MagicMock() # Act pde_solve(base_L, base_T, mock, base_mx, base_mt) # Assert assert mock.call_count == base_mx
def test_unit_ensures_that_u_I_is_called_with_correct_args(): # Arrange def fake_u_I(x): assert isinstance(x, float) == True # Act pde_solve(base_L, base_T, fake_u_I, base_mx, base_mt)
def test_unit_ensures_bcf_is_called_with_the_correct_params(): # Arrange def fake_bcf(t): assert type(t) == np.float64 return [0, 0] # Act pde_solve(base_L, base_T, base_u_I, base_mx, base_mt, bcf=fake_bcf)
def test_E2E_agaist_heat_equation_varying_diffusion_coefficient(): # Arrange # set problem parameters/functions L = 11 # length of spatial domain T = 0.5 # total time to solve for # set numerical parameters mx = 10 # number of gridpoints in space mt = 1000 # number of gridpoints in time # define initial params def u_I(x): # initial temperature distribution y = np.sin(pi * x / L) return y def heat_source(x, t): res = np.piecewise(x, [x < 5, x >= 5], [-1, 1]) return res # Act # solve the heat equation [u_j, x, t] = pde_solve(L, T, u_I, mx, mt, heat_source=heat_source) print("u_j {}".format(u_j)) assert np.isclose(u_j, [ 0, -863.00360932, -983.72884818, -972.80346348, -751.16896889, 753.06057621, 974.46691545, 984.96351132, 863.66058543, 0 ]).all()
def test_E2E_agaist_heat_equation_varying_bcf(): # Arrange # set problem parameters/functions kappa = 1 # diffusion constant L = 11 # length of spatial domain T = 0.5 # total time to solve for # set numerical parameters mx = 10 # number of gridpoints in space mt = 10 # number of gridpoints in time # define initial params def u_I(x): # initial temperature distribution y = np.sin(pi * x / L) return y def bcf(t): return [t, t] # Act # solve the heat equation [u_j, x, t] = pde_solve(L, T, u_I, mx, mt, bcf=bcf) # Assert # check solution at final value boundary conditions assert u_j[0] == T assert u_j[-1] == T
def test_unit_throws_if_not_passed_specified_params(): #Arrange thrown = False #Act try: res = pde_solve() except Exception as e: thrown = e #assert assert thrown != False
def test_E2E_agaist_exact_solution_to_heat_equation(): # Arrange # set problem parameters/functions kappa = 1 # diffusion constant L = 11 # length of spatial domain T = 0.5 # total time to solve for # set numerical parameters mx = 100 # number of gridpoints in space mt = 1000 # number of gridpoints in time # define initial params def u_I(x): # initial temperature distribution y = np.sin(pi * x / L) return y # define this to compare witht the exact solution def u_exact(x, t): # the exact solution y = np.exp(-kappa * (pi**2 / L**2) * t) * np.sin(pi * x / L) return y # Act # solve the heat equation [u_j, x, t] = pde_solve(L, T, u_I, mx, mt, f_kappa=lambda x: 1) # Assert looped = False # compare sol vs u_exact with error threashold for i in range(len(u_j)): exact = u_exact(x[i], T) assert isclose(u_j[i], exact, abs_tol=1e-3) looped = True assert looped == True
def test_E2E_agaist_heat_equation_varying_diffusion_coefficient(): # Arrange # set problem parameters/functions L = 11 # length of spatial domain T = 0.5 # total time to solve for # set numerical parameters mx = 10 # number of gridpoints in space mt = 1000 # number of gridpoints in time # define initial params def u_I(x): # initial temperature distribution y = np.sin(pi * x / L) return y # Act # solve the heat equation [u_j, x, t] = pde_solve(L, T, u_I, mx, mt, f_kappa=lambda x: x) print("u_j {}".format(u_j)) assert np.isclose(u_j, [ 0, 0.26789984, 0.40498984, 0.49342122, 0.52927611, 0.5140508, 0.45421537, 0.36018634, 0.24470462, 0.12086154, 0 ]).all()
def test_unit_ensure_returns(): # Arrange # Act res = pde_solve(base_L, base_T, base_u_I, base_mx, base_mt) # Assert assert res != None