diff --git a/examples/cvode_basic.py b/examples/cvode_basic.py index e453e804..35aeebf6 100644 --- a/examples/cvode_basic.py +++ b/examples/cvode_basic.py @@ -66,8 +66,8 @@ def f(t,y): pl.show() #Basic test - assert y2[-1][0] == pytest.approx(0.00347746, rel = 1e-5) - assert exp_sim.get_last_step() == pytest.approx(0.0222169642893, rel = 1e-3) + assert y2[-1][0] == pytest.approx(0.00347746, abs = 1e-5) + assert exp_sim.get_last_step() == pytest.approx(0.0222169642893, abs = 1e-3) return exp_mod, exp_sim diff --git a/examples/cvode_basic_backward.py b/examples/cvode_basic_backward.py index 4fc55f9f..fc076636 100644 --- a/examples/cvode_basic_backward.py +++ b/examples/cvode_basic_backward.py @@ -62,7 +62,7 @@ def f(t,y): pl.show() #Basic test - assert y[-1][0] == pytest.approx(4.00000000, rel = 1e-3) + assert y[-1][0] == pytest.approx(4.00000000, abs = 1e-3) return exp_mod, exp_sim diff --git a/examples/cvode_stability.py b/examples/cvode_stability.py index 706c97c9..346e9745 100644 --- a/examples/cvode_stability.py +++ b/examples/cvode_stability.py @@ -89,7 +89,7 @@ def f(t,y): #Basic test x1 = y[:,0] - assert_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1) + assert np.abs(float(x1[-1]) - 1.8601438) < 1e-1 return exp_mod, exp_sim diff --git a/examples/cvode_with_disc.py b/examples/cvode_with_disc.py index 96daa656..fec9d8e0 100644 --- a/examples/cvode_with_disc.py +++ b/examples/cvode_with_disc.py @@ -156,14 +156,11 @@ def run_example(with_plots=True): pl.show() #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) return exp_mod, exp_sim if __name__=="__main__": mod,sim = run_example() - - - diff --git a/examples/cvode_with_initial_sensitivity.py b/examples/cvode_with_initial_sensitivity.py index 4110fba5..ed1707e3 100644 --- a/examples/cvode_with_initial_sensitivity.py +++ b/examples/cvode_with_initial_sensitivity.py @@ -123,9 +123,9 @@ def f(t, y, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(1577.6552477, rel = 1e-5) - assert y[-1][1] == pytest.approx(611.9574565, rel = 1e-5) - assert y[-1][2] == pytest.approx(2215.88563217, rel = 1e-5) + assert y[-1][0] == pytest.approx(1577.6552477, abs = 1e-5) + assert y[-1][1] == pytest.approx(611.9574565, abs = 1e-5) + assert y[-1][2] == pytest.approx(2215.88563217, abs = 1e-5) assert exp_sim.p_sol[0][1][0] == pytest.approx(1.0) return exp_mod, exp_sim diff --git a/examples/cvode_with_jac.py b/examples/cvode_with_jac.py index f8885dd3..d5b02e74 100644 --- a/examples/cvode_with_jac.py +++ b/examples/cvode_with_jac.py @@ -78,8 +78,8 @@ def jac(t,y): pl.show() #Basic tests - assert_almost_equal(y[-1][0],-121.75000000,4) - assert_almost_equal(y[-1][1],-49.100000000) + assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4) + assert y[-1][1] == pytest.approx(-49.100000000) return exp_mod, exp_sim diff --git a/examples/cvode_with_jac_sparse.py b/examples/cvode_with_jac_sparse.py index fc77f31e..7ee70260 100644 --- a/examples/cvode_with_jac_sparse.py +++ b/examples/cvode_with_jac_sparse.py @@ -93,7 +93,7 @@ def jac(t,y): pl.show() #Basic tests - assert_almost_equal(y[-1][0],0.9851,3) + assert y[-1][0] == pytest.approx(0.9851, abs = 1e-3) return exp_mod, exp_sim diff --git a/examples/cvode_with_jac_spgmr.py b/examples/cvode_with_jac_spgmr.py index b797ecb8..d1ace07b 100644 --- a/examples/cvode_with_jac_spgmr.py +++ b/examples/cvode_with_jac_spgmr.py @@ -85,8 +85,8 @@ def jacv(t,y,fy,v): pl.show() #Basic tests - assert_almost_equal(y[-1][0],-121.75000000,4) - assert_almost_equal(y[-1][1],-49.100000000) + assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4) + assert y[-1][1] == pytest.approx(-49.100000000) return exp_mod, exp_sim diff --git a/examples/cvode_with_parameters.py b/examples/cvode_with_parameters.py index 021c1959..c7906c9c 100644 --- a/examples/cvode_with_parameters.py +++ b/examples/cvode_with_parameters.py @@ -87,12 +87,12 @@ def f(t, y, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, rel = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4) - assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials - assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8) - assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, rel = 1e-12) + assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) + assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) + assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) + assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials + assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) + assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12) return exp_mod, exp_sim diff --git a/examples/cvode_with_parameters_fcn.py b/examples/cvode_with_parameters_fcn.py index 62389c95..646ee55e 100644 --- a/examples/cvode_with_parameters_fcn.py +++ b/examples/cvode_with_parameters_fcn.py @@ -104,12 +104,12 @@ def fsens(t, y, s, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, rel = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4) - assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials - assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8) - assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, rel = 1e-12) + assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) + assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) + assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) + assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials + assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) + assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12) return exp_mod, exp_sim diff --git a/examples/cvode_with_parameters_modified.py b/examples/cvode_with_parameters_modified.py index 94624a87..8bd28f42 100644 --- a/examples/cvode_with_parameters_modified.py +++ b/examples/cvode_with_parameters_modified.py @@ -85,11 +85,11 @@ def f(t, y, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, rel = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4) - assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials - assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8) + assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) + assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) + assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) + assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials + assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) return exp_mod, exp_sim diff --git a/examples/cvode_with_preconditioning.py b/examples/cvode_with_preconditioning.py index 4d965727..84e34291 100644 --- a/examples/cvode_with_preconditioning.py +++ b/examples/cvode_with_preconditioning.py @@ -107,8 +107,8 @@ def prec_solve(t, y, fy, r, gamma, delta, data): exp_sim.plot() #Basic verification - assert_almost_equal(y[-1,0],3.11178295,4) - assert_almost_equal(y[-1,1],3.19318992,4) + assert y[-1,0] == pytest.approx(3.11178295, abs = 1e-4) + assert y[-1,1] == pytest.approx(3.19318992, abs = 1e-4) return exp_mod, exp_sim diff --git a/examples/dasp3_basic.py b/examples/dasp3_basic.py index a7a13934..ef78c244 100644 --- a/examples/dasp3_basic.py +++ b/examples/dasp3_basic.py @@ -100,7 +100,7 @@ def dzdt(t,y,z): pl.show() #Basic test - assert_almost_equal(y[-1,0], 10.860063849896818, 3) + assert y[-1,0] == pytest.approx( 10.860063849896818, abs = 1e-3) return exp_mod, exp_sim diff --git a/examples/dopri5_basic.py b/examples/dopri5_basic.py index 393b9427..36a83e67 100644 --- a/examples/dopri5_basic.py +++ b/examples/dopri5_basic.py @@ -56,7 +56,7 @@ def f(t,y): pl.show() #Basic test - assert_almost_equal(y[-1][0],0.02695199,5) + assert y[-1][0] == pytest.approx(0.02695199, abs = 1e-5) return exp_mod, exp_sim diff --git a/examples/dopri5_with_disc.py b/examples/dopri5_with_disc.py index 2c4ce9c5..92aa2002 100644 --- a/examples/dopri5_with_disc.py +++ b/examples/dopri5_with_disc.py @@ -155,9 +155,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) return exp_mod, exp_sim diff --git a/examples/euler_vanderpol.py b/examples/euler_vanderpol.py index 45af37bc..f4dc7109 100644 --- a/examples/euler_vanderpol.py +++ b/examples/euler_vanderpol.py @@ -86,7 +86,7 @@ def jac(t,y): #Basic test x1 = y[:,0] - assert_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1) + assert np.abs(float(x1[-1]) - 1.8601438) < 1e-1 return exp_mod, exp_sim diff --git a/examples/euler_with_disc.py b/examples/euler_with_disc.py index ecc7d3aa..3fcdb3c3 100644 --- a/examples/euler_with_disc.py +++ b/examples/euler_with_disc.py @@ -152,9 +152,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) return exp_mod, exp_sim diff --git a/examples/glimda_vanderpol.py b/examples/glimda_vanderpol.py index 993b71d3..8cc75939 100644 --- a/examples/glimda_vanderpol.py +++ b/examples/glimda_vanderpol.py @@ -86,7 +86,7 @@ def f(t,y,yd): #Basic test x1 = y[:,0] - assert float(x1[-1]) == pytest.approx(1.706168035, rel = 1e-3) + assert float(x1[-1]) == pytest.approx(1.706168035, abs = 1e-3) return imp_mod, imp_sim diff --git a/examples/ida_basic_backward.py b/examples/ida_basic_backward.py index fd6913bf..1ca05e37 100644 --- a/examples/ida_basic_backward.py +++ b/examples/ida_basic_backward.py @@ -62,7 +62,7 @@ def f(t,y,yd): pl.show() #Basic test - assert y[-1][0] == pytest.approx(4.00000000, rel = 1e-3) + assert y[-1][0] == pytest.approx(4.00000000, abs = 1e-3) return imp_mod, imp_sim diff --git a/examples/ida_with_disc.py b/examples/ida_with_disc.py index 9d0a3b6f..1b2ce144 100644 --- a/examples/ida_with_disc.py +++ b/examples/ida_with_disc.py @@ -158,9 +158,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) return imp_mod, imp_sim diff --git a/examples/ida_with_initial_sensitivity.py b/examples/ida_with_initial_sensitivity.py index d4bfad0e..7233202c 100644 --- a/examples/ida_with_initial_sensitivity.py +++ b/examples/ida_with_initial_sensitivity.py @@ -114,9 +114,9 @@ def f(t, y, yd,p): pl.show() #Basic test - assert_almost_equal(y[-1][0], 1577.6552477,3) - assert y[-1][1] == pytest.approx(611.9574565, rel = 1e-3) - assert y[-1][2] == pytest.approx(2215.88563217, rel = 1e-3) + assert y[-1][0] == pytest.approx(1577.6552477, abs = 1e-3) + assert y[-1][1] == pytest.approx(611.9574565, abs = 1e-3) + assert y[-1][2] == pytest.approx(2215.88563217, abs = 1e-3) assert imp_sim.p_sol[0][1][0] == pytest.approx(1.0) diff --git a/examples/ida_with_jac.py b/examples/ida_with_jac.py index a57d70ec..ac26d6a5 100644 --- a/examples/ida_with_jac.py +++ b/examples/ida_with_jac.py @@ -98,7 +98,7 @@ def jac(c,t,y,yd): #Sets the parameters imp_sim.atol = 1e-6 #Default 1e-6 imp_sim.rtol = 1e-6 #Default 1e-6 - imp_sim.suppress_alg = True #Suppres the algebraic variables on the error test + imp_sim.suppress_alg = True #Suppress the algebraic variables on the error test #Let Sundials find consistent initial conditions by use of 'IDA_YA_YDP_INIT' imp_sim.make_consistent('IDA_YA_YDP_INIT') @@ -107,10 +107,10 @@ def jac(c,t,y,yd): t, y, yd = imp_sim.simulate(5,1000) #Simulate 5 seconds with 1000 communication points #Basic tests - assert_almost_equal(y[-1][0],0.9401995, places=4) - assert_almost_equal(y[-1][1],-0.34095124, places=4) - assert yd[-1][0] == pytest.approx(-0.88198927, rel = 1e-4) - assert yd[-1][1] == pytest.approx(-2.43227069, rel = 1e-4) + assert y[-1][0] == pytest.approx(0.9401995, abs = 1e-4) + assert y[-1][1] == pytest.approx(-0.34095124, abs = 1e-4) + assert yd[-1][0] == pytest.approx(-0.88198927, abs = 1e-4) + assert yd[-1][1] == pytest.approx(-2.43227069, abs = 1e-4) #Plot if with_plots: diff --git a/examples/ida_with_jac_spgmr.py b/examples/ida_with_jac_spgmr.py index 5ae85f0d..fd759e56 100644 --- a/examples/ida_with_jac_spgmr.py +++ b/examples/ida_with_jac_spgmr.py @@ -77,8 +77,8 @@ def jacv(t,y,yd,res,v,c): t, y, yd = imp_sim.simulate(5, 1000) #Simulate 5 seconds with 1000 communication points #Basic tests - assert_almost_equal(y[-1][0],-121.75000000,4) - assert_almost_equal(y[-1][1],-49.100000000) + assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4) + assert y[-1][1] == pytest.approx(-49.100000000) #Plot if with_plots: diff --git a/examples/ida_with_parameters.py b/examples/ida_with_parameters.py index 0820ddc6..15a12e9b 100644 --- a/examples/ida_with_parameters.py +++ b/examples/ida_with_parameters.py @@ -66,7 +66,7 @@ def f(t, y, yd, p): #Sets the parameters imp_sim.atol = np.array([1.0e-8, 1.0e-14, 1.0e-6]) imp_sim.algvar = [1.0,1.0,0.0] - imp_sim.suppress_alg = False #Suppres the algebraic variables on the error test + imp_sim.suppress_alg = False #Suppress the algebraic variables on the error test imp_sim.report_continuously = True #Store data continuous during the simulation imp_sim.pbar = p0 imp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test. @@ -78,12 +78,12 @@ def f(t, y, yd, p): t, y, yd = imp_sim.simulate(4,400) #Simulate 4 seconds with 400 communication points #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, rel = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4) - assert imp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials - assert imp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8) - assert imp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, rel = 1e-12) + assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) + assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) + assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) + assert imp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials + assert imp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) + assert imp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12) #Plot if with_plots: diff --git a/examples/ida_with_user_defined_handle_result.py b/examples/ida_with_user_defined_handle_result.py index 090286ee..9414c412 100644 --- a/examples/ida_with_user_defined_handle_result.py +++ b/examples/ida_with_user_defined_handle_result.py @@ -81,7 +81,7 @@ def handle_result(solver, t ,y, yd): #Sets the parameters imp_sim.atol = 1e-6 #Default 1e-6 imp_sim.rtol = 1e-6 #Default 1e-6 - imp_sim.suppress_alg = True #Suppres the algebraic variables on the error test + imp_sim.suppress_alg = True #Suppress the algebraic variables on the error test imp_sim.report_continuously = True #Let Sundials find consistent initial conditions by use of 'IDA_YA_YDP_INIT' @@ -107,11 +107,11 @@ def handle_result(solver, t ,y, yd): pl.show() #Basic tests - assert_almost_equal(y[-1][0],0.9401995, places=4) - assert_almost_equal(y[-1][1],-0.34095124, places=4) - assert yd[-1][0] == pytest.approx(-0.88198927, rel = 1e-4) - assert yd[-1][1] == pytest.approx(-2.43227069, rel = 1e-4) - assert order[-1] == pytest.approx(5, rel = 1e-4) + assert y[-1][0] == pytest.approx(0.9401995, abs = 1e-4) + assert y[-1][1] == pytest.approx(-0.34095124, abs = 1e-4) + assert yd[-1][0] == pytest.approx(-0.88198927, abs = 1e-4) + assert yd[-1][1] == pytest.approx(-2.43227069, abs = 1e-4) + assert order[-1] == pytest.approx(5, abs = 1e-4) return imp_mod, imp_sim diff --git a/examples/kinsol_basic.py b/examples/kinsol_basic.py index 633d8216..d4af5d37 100644 --- a/examples/kinsol_basic.py +++ b/examples/kinsol_basic.py @@ -46,7 +46,7 @@ def res(y): y = alg_solver.solve() #Basic test - assert y == pytest.approx(1.0, rel = 1e-5) + assert y == pytest.approx(1.0, abs = 1e-5) return alg_mod, alg_solver diff --git a/examples/kinsol_ors.py b/examples/kinsol_ors.py index 5e39a9a7..a2c55b06 100644 --- a/examples/kinsol_ors.py +++ b/examples/kinsol_ors.py @@ -126,7 +126,7 @@ def setup_param(solver): #Basic test for j in range(len(y)): - assert y[j] == pytest.approx(1.0, rel = 1e-4) + assert y[j] == pytest.approx(1.0, abs = 1e-4) return [alg_mod, alg_mod_prec], [alg_solver, alg_solver_prec] diff --git a/examples/kinsol_with_jac.py b/examples/kinsol_with_jac.py index a6cb725d..235de43c 100644 --- a/examples/kinsol_with_jac.py +++ b/examples/kinsol_with_jac.py @@ -51,8 +51,8 @@ def jac(y): y = alg_solver.solve() #Basic test - assert y[0] == pytest.approx(1.5, rel = 1e-5) - assert y[1] == pytest.approx(1.0, rel = 1e-5) + assert y[0] == pytest.approx(1.5, abs = 1e-5) + assert y[1] == pytest.approx(1.0, abs = 1e-5) return alg_mod, alg_solver diff --git a/examples/lsodar_vanderpol.py b/examples/lsodar_vanderpol.py index 300da948..916a351f 100644 --- a/examples/lsodar_vanderpol.py +++ b/examples/lsodar_vanderpol.py @@ -75,7 +75,7 @@ def f(t,y): #Basic test x1 = y[:,0] - assert_less(np.abs(x1[-1] - 1.706168035), 1e-3) + assert np.abs(x1[-1] - 1.706168035) < 1e-3 return exp_mod, exp_sim diff --git a/examples/lsodar_with_disc.py b/examples/lsodar_with_disc.py index 398c4008..902f0463 100644 --- a/examples/lsodar_with_disc.py +++ b/examples/lsodar_with_disc.py @@ -152,9 +152,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) return exp_mod, exp_sim diff --git a/examples/mech_system_pendulum.py b/examples/mech_system_pendulum.py index cc9a6e79..19805285 100644 --- a/examples/mech_system_pendulum.py +++ b/examples/mech_system_pendulum.py @@ -60,7 +60,7 @@ def run_example(index="ind1", with_plots=True, with_test=False): print(final_residual, 'Norm: ', np.linalg.norm(final_residual)) if with_test: - assert_less(np.linalg.norm(final_residual), 1.5e-1) + assert np.linalg.norm(final_residual) < 1.5e-1 if with_plots: dae_pend.plot(mask=[1,1]+(len(my_pend.y0)-2)*[0]) return my_pend, dae_pend diff --git a/examples/radau5dae_time_events.py b/examples/radau5dae_time_events.py index 7e23e215..0780e34b 100644 --- a/examples/radau5dae_time_events.py +++ b/examples/radau5dae_time_events.py @@ -73,7 +73,7 @@ def run_example(with_plots=True): #Basic test x1 = y[:,0] - assert_less(np.abs(float(x1[-1]) - 1.14330840983), 1e-3) + assert np.abs(float(x1[-1]) - 1.14330840983) < 1e-3 return imp_mod, imp_sim if __name__=='__main__': diff --git a/examples/radau5dae_vanderpol.py b/examples/radau5dae_vanderpol.py index 65e35a59..6dec4d00 100644 --- a/examples/radau5dae_vanderpol.py +++ b/examples/radau5dae_vanderpol.py @@ -86,7 +86,7 @@ def f(t,y,yd): #Basic test x1 = y[:,0] - assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3) + assert np.abs(float(x1[-1]) - 1.706168035) < 1e-3 return imp_mod, imp_sim diff --git a/examples/radau5ode_vanderpol.py b/examples/radau5ode_vanderpol.py index da6f81d4..577b856a 100644 --- a/examples/radau5ode_vanderpol.py +++ b/examples/radau5ode_vanderpol.py @@ -76,7 +76,7 @@ def f(t,y): #Basic test x1 = y[:,0] - assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3) + assert np.abs(float(x1[-1]) - 1.706168035) < 1e-3 return exp_mod, exp_sim diff --git a/examples/radau5ode_with_disc.py b/examples/radau5ode_with_disc.py index 17acc0a9..8311d413 100644 --- a/examples/radau5ode_with_disc.py +++ b/examples/radau5ode_with_disc.py @@ -134,9 +134,9 @@ def run_example(with_plots=True): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) #Plot if with_plots: diff --git a/examples/radau5ode_with_disc_sparse.py b/examples/radau5ode_with_disc_sparse.py index c80b55c6..c7b796cc 100644 --- a/examples/radau5ode_with_disc_sparse.py +++ b/examples/radau5ode_with_disc_sparse.py @@ -142,9 +142,9 @@ def run_example(with_plots=True): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) #Plot if with_plots: diff --git a/examples/radau5ode_with_jac_sparse.py b/examples/radau5ode_with_jac_sparse.py index 1553ab24..00b99521 100644 --- a/examples/radau5ode_with_jac_sparse.py +++ b/examples/radau5ode_with_jac_sparse.py @@ -89,7 +89,7 @@ def jac(t,y): pl.show() #Basic tests - assert y[-1][0] == pytest.approx(0.9851, rel = 1e-3) + assert y[-1][0] == pytest.approx(0.9851, abs = 1e-3) return exp_mod, exp_sim diff --git a/examples/rodasode_vanderpol.py b/examples/rodasode_vanderpol.py index 1abc2533..d1ec8777 100644 --- a/examples/rodasode_vanderpol.py +++ b/examples/rodasode_vanderpol.py @@ -86,7 +86,7 @@ def jac(t,y): #Basic test x1 = y[:,0] - assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3) + assert np.abs(float(x1[-1]) - 1.706168035) < 1e-3 return exp_mod, exp_sim diff --git a/examples/rungekutta34_basic.py b/examples/rungekutta34_basic.py index 3037a451..273e9363 100644 --- a/examples/rungekutta34_basic.py +++ b/examples/rungekutta34_basic.py @@ -49,7 +49,7 @@ def f(t,y): t, y = exp_sim.simulate(5) #Simulate 5 seconds #Basic test - assert y[-1][0] == pytest.approx(0.02695199, rel = 1e-5) + assert y[-1][0] == pytest.approx(0.02695199, abs = 1e-5) #Plot if with_plots: diff --git a/examples/rungekutta34_with_disc.py b/examples/rungekutta34_with_disc.py index fe84ea06..9df65b2b 100644 --- a/examples/rungekutta34_with_disc.py +++ b/examples/rungekutta34_with_disc.py @@ -136,9 +136,9 @@ def run_example(with_plots=True): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) #Plot if with_plots: diff --git a/src/problem.pyx b/src/problem.pyx index 6e4ebbb3..a394f19f 100644 --- a/src/problem.pyx +++ b/src/problem.pyx @@ -166,7 +166,7 @@ cdef class cExplicit_Problem(cProblem): return ID_OK cpdef np.ndarray res(self, t, y, yd, sw=None): - if sw == None: + if sw is None: return yd-self.rhs(t,y) else: return yd-self.rhs(t, y, sw) diff --git a/src/solvers/sdirk_dae.pyx b/src/solvers/sdirk_dae.pyx index f5668503..b4d35ba3 100644 --- a/src/solvers/sdirk_dae.pyx +++ b/src/solvers/sdirk_dae.pyx @@ -144,7 +144,7 @@ class SDIRK_DAE(Implicit_ODE): #Run in normal mode? normal_mode = 1 if opts["output_list"] != None else 0 #if normal_mode == 0: - if opts["report_continuously"] or opts["output_list"] == None: + if opts["report_continuously"] or opts["output_list"] is None: while (ISTATE == 2 or ISTATE == 1) and t < tf: y, t, ISTATE, RWORK, IWORK, roots = dlsodar(self.problem.rhs, y.copy(), t, tf, ITOL, diff --git a/tests/solvers/test_euler.py b/tests/solvers/test_euler.py index 87e1b7c7..0cf2e412 100644 --- a/tests/solvers/test_euler.py +++ b/tests/solvers/test_euler.py @@ -119,6 +119,7 @@ def init_mode(self, solver): class Test_Explicit_Euler: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. @@ -271,6 +272,7 @@ def f(t, y): class Test_Implicit_Euler: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. @@ -306,13 +308,13 @@ def test_usejac_csc_matrix(self): exp_sim.simulate(5.,100) assert exp_sim.statistics["nfcnjacs"] == 0 - assert exp_sim.y_sol[-1][0] == pytest.approx(-121.995500, rel = 1e-4) + assert exp_sim.y_sol[-1][0] == pytest.approx(-121.995500, abs = 1e-4) exp_sim.reset() exp_sim.usejac=False exp_sim.simulate(5.,100) - assert exp_sim.y_sol[-1][0] == pytest.approx(-121.995500, rel = 1e-4) + assert exp_sim.y_sol[-1][0] == pytest.approx(-121.995500, abs = 1e-4) assert exp_sim.statistics["nfcnjacs"] > 0 @testattr(stddist = True) diff --git a/tests/solvers/test_glimda.py b/tests/solvers/test_glimda.py index 59cc28db..c16fc913 100644 --- a/tests/solvers/test_glimda.py +++ b/tests/solvers/test_glimda.py @@ -28,6 +28,7 @@ class Test_GLIMDA: Tests the GLIMDA solver. """ @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. diff --git a/tests/solvers/test_odassl.py b/tests/solvers/test_odassl.py index 099c9cce..82a76d4c 100644 --- a/tests/solvers/test_odassl.py +++ b/tests/solvers/test_odassl.py @@ -25,6 +25,7 @@ class Test_ODASSL: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. diff --git a/tests/solvers/test_odepack.py b/tests/solvers/test_odepack.py index 212a9b97..297bbb91 100644 --- a/tests/solvers/test_odepack.py +++ b/tests/solvers/test_odepack.py @@ -123,6 +123,7 @@ class Test_LSODAR: Tests the LSODAR solver. """ @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. @@ -192,9 +193,9 @@ def test_event_localizer(self): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) @testattr(stddist = True) def test_simulation(self): @@ -203,13 +204,13 @@ def test_simulation(self): """ self.sim.simulate(1.) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, abs = 1e-4) @testattr(stddist = True) def test_setcoefficients(self): elco,tesco=dcfode(1) - assert_almost_equal(elco[0,2],5./12.,9) # AM-2 - assert_almost_equal(tesco[0,2],2.,9) # AM-2 error coeff + assert elco[0,2] == pytest.approx(5./12., abs = 1e-9) # AM-2 + assert tesco[0,2] == pytest.approx(2., abs = 1e-9) # AM-2 error coeff @testattr(stddist = True) def test_readcommon(self): @@ -220,7 +221,7 @@ def test_readcommon(self): r=np.ones((245,),'d') i=np.ones((55,),'i') dsrcar(r,i,1) - assert r[217] == pytest.approx(2.22044605e-16, rel = 1e-20) + assert r[217] == pytest.approx(2.22044605e-16, abs = 1e-20) assert i[36] == 3 @testattr(stddist = True) @@ -234,7 +235,7 @@ def test_writereadcommon(self): r[0]=100. i[0]=10 dsrcar(r,i,1) - assert r[0] == pytest.approx(1., rel = 1e-4) + assert r[0] == pytest.approx(1., abs = 1e-4) assert i[0] == 1 def test_rkstarter(self): @@ -276,7 +277,7 @@ def test_interpol(self): self.sim.reset() t_sol1,y_sol1=self.sim.simulate(0.5) ind05=np.nonzero(np.array(t_sol)==0.5)[0][0] - assert_almost_equal(y_sol[ind05,0],y_sol1[-1,0],6) + assert y_sol[ind05,0] == pytest.approx(y_sol1[-1,0], abs = 1e-6) @testattr(stddist = True) def test_simulation_with_jac(self): @@ -286,13 +287,13 @@ def test_simulation_with_jac(self): self.sim.usejac = True self.sim.simulate(1.) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, abs = 1e-4) @testattr(stddist = True) def test_simulation_ncp(self): self.sim.simulate(1.,100) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, abs = 1e-4) @testattr(stddist = True) def test_usejac_csc_matrix(self): @@ -302,13 +303,13 @@ def test_usejac_csc_matrix(self): assert self.sim_sp.statistics["nfcnjacs"] == 0 - assert self.sim_sp.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim_sp.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_simulation_ncp_list(self): self.sim.simulate(1.,ncp_list=[0.5]) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, abs = 1e-4) @testattr(stddist = True) def test_maxh(self): @@ -325,7 +326,7 @@ def test_maxh(self): def test_simulation_ncp_list_2(self): self.sim.simulate(1.,ncp_list=[0.5,4]) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, abs = 1e-4) @testattr(stddist = True) def test_simulation_ncp_with_jac(self): @@ -335,7 +336,7 @@ def test_simulation_ncp_with_jac(self): self.sim.usejac= True self.sim.simulate(1.,100) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, abs = 1e-4) @testattr(stddist = True) def test_time_limit(self): diff --git a/tests/solvers/test_radau5.py b/tests/solvers/test_radau5.py index 24a11710..641398f3 100644 --- a/tests/solvers/test_radau5.py +++ b/tests/solvers/test_radau5.py @@ -170,6 +170,7 @@ class Test_Explicit_Radau5_Py: Tests the explicit Radau solver (Python implementation). """ @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. @@ -227,9 +228,9 @@ def test_event_localizer(self): # t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points # #Basic test - # assert_almost_equal(y[-1][0],8.0) - # assert_almost_equal(y[-1][1],3.0) - # assert_almost_equal(y[-1][2],2.0) + # assert y[-1][0] == pytest.approx(8.0) + # assert y[-1][1] == pytest.approx(3.0) + # assert y[-1][2] == pytest.approx(2.0) @testattr(stddist = True) def test_time_event(self): @@ -286,9 +287,9 @@ def test_collocation_polynomial(self): assert self.sim.statistics["nsteps"] < 300 - #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4) + #assert self.sim.y[-2][0] == pytest.approx(1.71505001, abs = 1e-4) print - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) self.sim.report_continuously = True self.sim.reset() @@ -296,13 +297,13 @@ def test_collocation_polynomial(self): assert self.sim.statistics["nsteps"] < 300 - #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4) - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + #assert self.sim.y[-2][0] == pytest.approx(1.71505001, abs = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) self.sim_t0.simulate(3.) - assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4) - assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4) - assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, abs = 1e-4) + assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, abs = 1e-4) + assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_simulation(self): @@ -313,7 +314,7 @@ def test_simulation(self): assert self.sim.statistics["nsteps"] < 300 - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_simulation_ncp(self): @@ -342,7 +343,7 @@ def test_usejac(self): assert self.sim.statistics["nfcnjacs"] == 0 - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_thet(self): @@ -422,7 +423,7 @@ def test_atol(self): assert steps3 == steps2 err_msg = "atol must be of length one or same as the dimension of the problem." - with pytest.raises(Radau_Exception, err_msg): + with pytest.raises(Radau_Exception, match = err_msg): self.sim.atol = [1e-6,1e-6,1e-6] class Test_Explicit_Radau5: @@ -430,6 +431,7 @@ class Test_Explicit_Radau5: Tests the explicit Radau solver. """ @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. @@ -501,9 +503,9 @@ def test_event_localizer(self): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert_almost_equal(y[-1][0],8.0) - assert_almost_equal(y[-1][1],3.0) - assert_almost_equal(y[-1][2],2.0) + assert y[-1][0] == pytest.approx(8.0) + assert y[-1][1] == pytest.approx(3.0) + assert y[-1][2] == pytest.approx(2.0) @testattr(stddist = True) def test_nbr_fcn_evals_due_to_jac(self): @@ -574,8 +576,8 @@ def test_collocation_polynomial(self): assert self.sim.statistics["nsteps"] < 300 - #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4) - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + #assert self.sim.y[-2][0] == pytest.approx(1.71505001, abs = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) self.sim.report_continuously = True self.sim.reset() @@ -583,13 +585,13 @@ def test_collocation_polynomial(self): assert self.sim.statistics["nsteps"] < 300 - #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4) - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + #assert self.sim.y[-2][0] == pytest.approx(1.71505001, abs = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) self.sim_t0.simulate(3.) - assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4) - assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4) - assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, abs = 1e-4) + assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, abs = 1e-4) + assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_simulation(self): @@ -600,7 +602,7 @@ def test_simulation(self): assert self.sim.statistics["nsteps"] < 300 - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_simulation_ncp(self): @@ -629,7 +631,7 @@ def test_usejac(self): assert self.sim.statistics["nfcnjacs"] == 0 - assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_usejac_csc_matrix(self): @@ -642,7 +644,7 @@ def test_usejac_csc_matrix(self): assert self.sim_sp.statistics["nfcnjacs"] == 0 - assert self.sim_sp.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim_sp.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_thet(self): @@ -673,7 +675,7 @@ def test_newt(self): # self.sim.reset() # self.sim.newt = 10 # self.sim.simulate(1.0) - # assert_equal(self.sim.statistics["nniterfail"], 1) + # assert self.sim.statistics["nniterfail"] == 1 @testattr(stddist = True) def test_safe(self): @@ -738,7 +740,7 @@ def test_atol(self): assert steps3 == steps2 err_msg = "atol must be of length one or same as the dimension of the problem." - with pytest.raises(Radau_Exception, err_msg): + with pytest.raises(Radau_Exception, match = err_msg): self.sim.atol = [1e-6,1e-6,1e-6] @testattr(stddist = True) @@ -773,7 +775,7 @@ def test_nmax_steps(self): sim.maxsteps = 9 err_msg = f'Radau5 failed with flag -5. At time {float_regex}. Message: Maximal number of steps = 9 exceeded.' - with pytest.raises(Radau5Error, err_msg): + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) @testattr(stddist = True) @@ -790,7 +792,7 @@ def test_step_size_too_small(self): sim.maxh = 1.e-1 err_msg = f"Radau5 failed with flag -6. At time {float_regex}. Message: Stepsize too small with h = {float_regex}." - with pytest.raises(Radau5Error, err_msg): + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1. + 1.e-16) @testattr(stddist = True) @@ -805,7 +807,7 @@ def f(t, y): sim = Radau5ODE(prob) err_msg = f'Repeated unexpected step rejections.' - with pytest.raises(Radau5Error, err_msg): + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) @testattr(stddist = True) @@ -837,7 +839,7 @@ def test_solver_no_jac(self): sim.usejac = True err_msg = "Use of an analytical Jacobian is enabled, but problem does contain a 'jac' function." - with pytest.raises(Radau_Exception, err_msg): + with pytest.raises(Radau_Exception, match = err_msg): sim.simulate(1.) @testattr(stddist = True) @@ -857,7 +859,7 @@ def test_solver_sparse_jac_wrong_format(self): sim.usejac = True err_msg = f'Radau5 failed with flag -11. At time {float_regex}. Message: Jacobian given in wrong format, required sparsity format: CSC.' - with pytest.raises(Radau5Error, err_msg): + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) @testattr(stddist = True) @@ -878,7 +880,7 @@ def test_solver_sparse_jac_nnz_too_small(self): sim.usejac = True err_msg = f'Radau5 failed with flag -9. At time {float_regex}. Message: Number of nonzero elements in provided jacobian is too small, specified = 1, actual = 5.' - with pytest.raises(Radau5Error, err_msg): + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) @testattr(stddist = True) @@ -916,7 +918,7 @@ def test_sparse_solver_no_nnz(self): sim.usejac = True err_msg = "Number of non-zero elements of sparse Jacobian must be non-negative. Detected default value of '-1', has 'problem.jac_fcn_nnz' been set?" - with pytest.raises(Radau_Exception, err_msg): + with pytest.raises(Radau_Exception, match = err_msg): sim.simulate(1.) @testattr(stddist = True) @@ -938,7 +940,7 @@ def test_sparse_solver_invalid_nnz_type(self): sim.usejac = True err_msg = "Number of non-zero elements of sparse Jacobian must be an integer, received: {}." - with pytest.raises(Radau_Exception, err_msg.format(nnz)): + with pytest.raises(Radau_Exception, match = err_msg.format(nnz)): sim.simulate(1.) @testattr(stddist = True) @@ -960,7 +962,7 @@ def test_sparse_solver_invalid_nnz_negative(self): sim.usejac = True err_msg = "Number of non-zero elements of sparse Jacobian must be non-negative, given value = {}." - with pytest.raises(Radau_Exception, err_msg.format(nnz)): + with pytest.raises(Radau_Exception, match = err_msg.format(nnz)): sim.simulate(1.) @testattr(stddist = True) @@ -982,7 +984,7 @@ def test_sparse_solver_invalid_nnz_too_large(self): sim.usejac = True err_msg = "Number of non-zero elements of sparse Jacobian infeasible, must be smaller than the problem dimension squared." - with pytest.raises(Radau_Exception, err_msg): + with pytest.raises(Radau_Exception, match = err_msg): sim.simulate(1.) def test_sparse_solver_jacobian(self): @@ -1011,7 +1013,7 @@ def test_sparse_solver_jacobian(self): sim.linear_solver = 'SPARSE' sim.usejac = True - ok_(sim.simulate(1.), msg = f"Jacobian #{i} failed: {jac(0, 0)}") + assert sim.simulate(1.), f"Jacobian #{i} failed: {jac(0, 0)}" @testattr(stddist = True) def test_linear_solver(self): @@ -1028,13 +1030,13 @@ def test_linear_solver(self): assert self.sim.linear_solver == 'SPARSE' err_msg = "'linear_solver' parameter needs to be either 'DENSE' or 'SPARSE'. Set value: {}" - with pytest.raises(Radau_Exception, err_msg.format('default')): + with pytest.raises(Radau_Exception, match = err_msg.format('default')): self.sim.linear_solver = 'default' - with pytest.raises(Radau_Exception, err_msg.format('GMRES')): + with pytest.raises(Radau_Exception, match = err_msg.format('GMRES')): self.sim.linear_solver = 'GMRES' err_msg = "'linear_solver' parameter needs to be the STRING 'DENSE' or 'SPARSE'. Set value: {}, type: {}" - with pytest.raises(Radau_Exception, err_msg.format('0', "")): + with pytest.raises(Radau_Exception, match = err_msg.format('0', "")): self.sim.linear_solver = 0 @testattr(stddist = True) @@ -1157,6 +1159,7 @@ class Test_Implicit_Radau5: Tests the implicit Radau solver. """ @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. @@ -1202,7 +1205,7 @@ def test_implementation_set(self): Test setting of implementation property of Radau5DAE. """ err_msg = "Radau5DAE does not support setting the 'implementation' attribute, since it only supports the Fortran implementation of Radau5." - with pytest.raises(Radau_Exception, err_msg): + with pytest.raises(Radau_Exception, match = err_msg): self.sim.implementation = 'c' @testattr(stddist = True) @@ -1218,7 +1221,7 @@ def test_linear_solver_set(self): Test setting of linear_solver property of Radau5DAE. """ err_msg = "Radau5DAE does not support setting the 'linear_solver' attribute, since it only supports the DENSE linear solver in Fortran implementation of Radau5." - with pytest.raises(Radau_Exception, err_msg): + with pytest.raises(Radau_Exception, match = err_msg): self.sim.linear_solver = 'SPARSE' @testattr(stddist = True) @@ -1311,7 +1314,7 @@ def test_simulation(self): """ #Simulate self.sim.simulate(2.) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(1.706272, rel = 1e-3) + assert self.sim.y_sol[-1][0] == pytest.approx(1.706272, abs = 1e-3) self.sim.reset() @@ -1319,12 +1322,12 @@ def test_simulation(self): #Simulate self.sim.simulate(2.) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(1.706166, rel = 1e-3) + assert self.sim.y_sol[-1][0] == pytest.approx(1.706166, abs = 1e-3) self.sim_t0.simulate(3.) - assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4) - assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4) - assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, abs = 1e-4) + assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, abs = 1e-4) + assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_simulation_ncp(self): @@ -1384,7 +1387,7 @@ def test_nmax_steps(self): sim.maxsteps = 9 err_msg = "The solver took max internal steps but could not reach the next output time." - with pytest.raises(Radau5Error, err_msg): + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) @testattr(stddist = True) @@ -1407,7 +1410,7 @@ def test_step_size_too_small(self): sim.maxh = 1.e-1 err_msg = f"The step size became too small. At time {float_regex}." - with pytest.raises(Radau5Error, err_msg): + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1. + 1.e-16) @testattr(stddist = True) @@ -1420,8 +1423,8 @@ def f(t, y, yd): prob = Implicit_Problem(f, np.array([1.]), np.array([1.])) sim = Radau5DAE(prob) - err_msg = f'Repeated unexpected step rejections.' - with pytest.raises(Radau5Error, err_msg): + err_msg = 'Repeated unexpected step rejections.' + with pytest.raises(Radau5Error, match = err_msg): sim.simulate(1.) @@ -1430,6 +1433,7 @@ class Test_Implicit_Radau5_Py: Tests the implicit Radau solver (Python implementation). """ @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. @@ -1527,7 +1531,7 @@ def test_simulation(self): """ #Simulate self.sim.simulate(2.) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(1.706272, rel = 1e-3) + assert self.sim.y_sol[-1][0] == pytest.approx(1.706272, abs = 1e-3) self.sim.reset() @@ -1535,12 +1539,12 @@ def test_simulation(self): #Simulate self.sim.simulate(2.) #Simulate 2 seconds - assert self.sim.y_sol[-1][0] == pytest.approx(1.706947, rel = 1e-2) + assert self.sim.y_sol[-1][0] == pytest.approx(1.706947, abs = 1e-2) self.sim_t0.simulate(3.) - assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4) - assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4) - assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, abs = 1e-4) + assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, abs = 1e-4) + assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_simulation_ncp(self): @@ -1578,7 +1582,7 @@ def test_keyboard_interrupt_fcn(self): sim = Radau5DAE(prob) err_msg = "Unrecoverable exception encountered during callback to problem (right-hand side/jacobian)." - with pytest.raises(Radau5Error, re.escape(err_msg)): + with pytest.raises(Radau5Error, match = re.escape(err_msg)): sim.simulate(1.) class Test_Radau_Common: @@ -1586,6 +1590,7 @@ class Test_Radau_Common: Tests the common attributes of the Radau solvers. """ @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. diff --git a/tests/solvers/test_rosenbrock.py b/tests/solvers/test_rosenbrock.py index 79f9b270..19ef8399 100644 --- a/tests/solvers/test_rosenbrock.py +++ b/tests/solvers/test_rosenbrock.py @@ -27,6 +27,7 @@ class Test_RodasODE: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): #Define the rhs def f(t,y): @@ -90,7 +91,7 @@ def test_usejac_csc_matrix(self): assert sim.statistics["nfcnjacs"] == 0 - assert sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4) + assert sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4) @testattr(stddist = True) def test_time_limit(self): diff --git a/tests/solvers/test_rungekutta.py b/tests/solvers/test_rungekutta.py index a36aaec3..33927b00 100644 --- a/tests/solvers/test_rungekutta.py +++ b/tests/solvers/test_rungekutta.py @@ -27,6 +27,7 @@ class Test_Dopri5: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. @@ -125,6 +126,7 @@ def f(t, y): class Test_RungeKutta34: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. @@ -261,6 +263,7 @@ def f(t, y): class Test_RungeKutta4: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. diff --git a/tests/solvers/test_sundials.py b/tests/solvers/test_sundials.py index 853d2e58..78c65f49 100644 --- a/tests/solvers/test_sundials.py +++ b/tests/solvers/test_sundials.py @@ -117,6 +117,7 @@ def init_mode(self, solver): class Test_CVode: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. @@ -201,7 +202,7 @@ def test_get_used_initial_step(self): self.simulator.simulate(1.0) step = self.simulator.get_used_initial_step() - assert step == pytest.approx(0.001, rel = 1e-3) + assert step == pytest.approx(0.001, abs = 1e-3) self.simulator.reset() @@ -279,7 +280,7 @@ def test_init(self): """ This tests the functionality of the method __init__. """ - # assert_equal(self.simulator.f, 'Test function') + # assert self.simulator.f == 'Test function' assert self.simulator.y == 1.0 assert self.simulator.discr == 'BDF' assert self.simulator.iter == 'Newton' @@ -496,13 +497,13 @@ def test_usejac(self): exp_sim.simulate(5.,100) assert exp_sim.statistics["nfcnjacs"] == 0 - assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4) + assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, abs = 1e-4) exp_sim.reset() exp_sim.usejac=False exp_sim.simulate(5.,100) - assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4) + assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, abs = 1e-4) assert exp_sim.statistics["nfcnjacs"] > 0 @testattr(stddist = True) @@ -522,13 +523,13 @@ def test_usejac_csc_matrix(self): exp_sim.simulate(5.,100) assert exp_sim.statistics["nfcnjacs"] == 0 - assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4) + assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, abs = 1e-4) exp_sim.reset() exp_sim.usejac=False exp_sim.simulate(5.,100) - assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4) + assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, abs = 1e-4) assert exp_sim.statistics["nfcnjacs"] > 0 @testattr(stddist = True) @@ -608,7 +609,7 @@ def test_interpolate(self): t100 = sim.t_sol sim.reset() sim.simulate(10.) - assert_almost_equal(float(y100[-2]), float(sim.interpolate(9.9,0)),5) + assert float(y100[-2]) == pytest.approx(float(sim.interpolate(9.9, 0)), abs = 1e-5) @testattr(stddist = True) def test_ncp_list(self): @@ -620,7 +621,7 @@ def test_ncp_list(self): t, y = sim.simulate(7, ncp_list=np.arange(0, 7, 0.1)) #Simulate 5 seconds - assert float(y[-1]) == pytest.approx(0.00364832, rel = 1e-4) + assert float(y[-1]) == pytest.approx(0.00364832, abs = 1e-4) @testattr(stddist = True) def test_handle_result(self): @@ -691,8 +692,8 @@ def run_sim(exp_mod): t, y = exp_sim.simulate(5, 1000) #Simulate 5 seconds with 1000 communication points #Basic tests - assert_almost_equal(y[-1][0],-121.75000000,4) - assert_almost_equal(y[-1][1],-49.100000000) + assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4) + assert y[-1][1] == pytest.approx(-49.100000000) exp_mod = Explicit_Problem(f,y0) exp_mod.jacv = jacv #Sets the jacobian @@ -821,7 +822,7 @@ def handle_event(self, solver, event_info): simulator = CVode(exp_mod) simulator(3.) - assert simulator.t == pytest.approx(2.000000, rel = 1e-4) + assert simulator.t == pytest.approx(2.000000, abs = 1e-4) @testattr(stddist = True) def test_completed_step(self): @@ -919,6 +920,7 @@ def test_rtol_vector_sense(self): class Test_IDA: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This function sets up the test case. @@ -968,7 +970,7 @@ def test_init(self): """ assert not self.simulator.suppress_alg assert self.simulator.algvar[0] == 1.0 - assert self.simulator.sw == None + assert self.simulator.sw is None assert self.simulator.maxsteps == 10000 assert self.simulator.y[0] == 1.0 @@ -987,7 +989,7 @@ def test_interpolate(self): t100 = sim.t_sol sim.reset() sim.simulate(10.) - assert_almost_equal(y100[-2], sim.interpolate(9.9,0),5) + assert y100[-2] == pytest.approx(sim.interpolate(9.9, 0), abs = 1e-5) @testattr(stddist = True) def test_handle_result(self): @@ -1071,13 +1073,13 @@ def f(t,y,yd): sim = IDA(mod) sim.simulate(2.0) - assert sim.y_sol[-1][0] == pytest.approx(-13.4746473811, rel = 1e-7) + assert sim.y_sol[-1][0] == pytest.approx(-13.4746473811, abs = 1e-7) sim.reset() sim.inith = 1e-10 sim.simulate(2.0) - assert sim.y_sol[-1][0] == pytest.approx(-13.4746596311, rel = 1e-7) + assert sim.y_sol[-1][0] == pytest.approx(-13.4746596311, abs = 1e-7) @testattr(stddist = True) def test_time_event(self): @@ -1114,9 +1116,9 @@ def handle_event(solver, event_info): sim.simulate(5.0) - assert sim.y_sol[38] == pytest.approx(1.0000000, rel = 1e-5) - assert sim.y_sol[87] == pytest.approx(1.0000000, rel = 1e-5) - assert sim.t_sol[-1] == pytest.approx(5.0000000, rel = 1e-5) + assert sim.y_sol[38] == pytest.approx(1.0000000, abs = 1e-5) + assert sim.y_sol[87] == pytest.approx(1.0000000, abs = 1e-5) + assert sim.t_sol[-1] == pytest.approx(5.0000000, abs = 1e-5) @testattr(stddist = True) def test_clear_event_log(self): @@ -1175,13 +1177,13 @@ def test_usejac(self): imp_sim.simulate(3,100) assert imp_sim.statistics["nfcnjacs"] == 0 - assert imp_sim.y_sol[-1][0] == pytest.approx(45.1900000, rel = 1e-4) + assert imp_sim.y_sol[-1][0] == pytest.approx(45.1900000, abs = 1e-4) imp_sim.reset() imp_sim.usejac=False imp_sim.simulate(3.,100) - assert imp_sim.y_sol[-1][0] == pytest.approx(45.1900000, rel = 1e-4) + assert imp_sim.y_sol[-1][0] == pytest.approx(45.1900000, abs = 1e-4) assert imp_sim.statistics["nfcnjacs"] > 0 @testattr(stddist = True) @@ -1204,7 +1206,7 @@ def handle_event(self,solver, event_info): sim = IDA(prob) sim.simulate(2.5) - assert sim.t == pytest.approx(2.000000, rel = 1e-4) + assert sim.t == pytest.approx(2.000000, abs = 1e-4) @testattr(stddist = True) def test_terminate_simulation_external_event(self): @@ -1227,7 +1229,7 @@ def handle_event(self,solver, event_info): sim.external_event_detection = True sim.simulate(2.5) - assert sim.t == pytest.approx(2.000000, rel = 1e-4) + assert sim.t == pytest.approx(2.000000, abs = 1e-4) @testattr(stddist = True) def test_algvar(self): @@ -1258,9 +1260,9 @@ def test_algvar(self): #self.simulator.algvar = vectorb #self.simulator.algvar = vectori #self.simulator.algvar = vector - #assert_equal(self.simulator.algvar[0], vector[0]) - #assert_equal(self.simulator.algvar[1], vector[1]) - #assert_equal(self.simulator.algvar[2], vector[2]) + #assert self.simulator.algvar[0] == vector[0] + #assert self.simulator.algvar[1] == vector[1] + #assert self.simulator.algvar[2] == vector[2] @testattr(stddist = True) def test_time_event_2(self): @@ -1390,6 +1392,7 @@ def completed_step(solver): class Test_Sundials: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): """ This sets up the test case. @@ -1456,11 +1459,11 @@ def test_atol(self): with pytest.raises(Exception): self.simulators([i]._set_atol, [1.0, 1.0, -1.0]) self.simulators[i].atol = [1.0, 1.0, 1.0] - assert_equal(self.simulators[i].atol, [1.0, 1.0, 1.0]) + assert self.simulators[i].atol == [1.0, 1.0, 1.0] self.simulators[i].atol = np.array([1.0, 1.0, 1.0]) - assert_equal(self.simulators[i].atol[0], 1.0) + assert self.simulators[i].atol[0] == 1.0 self.simulators[i].atol = np.array([1, 5, 1.0]) - assert_equal(self.simulators[i].atol[0], 1.0) + assert self.simulators[i].atol[0] == 1.0 """ @@ -1636,8 +1639,8 @@ def test_pbar(self): exp_sim = CVode(exp_mod) - assert exp_sim.pbar[0] == pytest.approx(1000.00000, rel = 1e-4) - assert exp_sim.pbar[1] == pytest.approx(100.000000, rel = 1e-4) + assert exp_sim.pbar[0] == pytest.approx(1000.00000, abs = 1e-4) + assert exp_sim.pbar[1] == pytest.approx(100.000000, abs = 1e-4) f = lambda t,y,yd,p: np.array([0.0]*len(y)) yd0 = [0.0]*2 @@ -1645,5 +1648,5 @@ def test_pbar(self): imp_sim = IDA(imp_mod) - assert imp_sim.pbar[0] == pytest.approx(1000.00000, rel = 1e-4) - assert imp_sim.pbar[1] == pytest.approx(100.000000, rel = 1e-4) + assert imp_sim.pbar[0] == pytest.approx(1000.00000, abs = 1e-4) + assert imp_sim.pbar[1] == pytest.approx(100.000000, abs = 1e-4) diff --git a/tests/test_ode.py b/tests/test_ode.py index f67a808a..83429e69 100644 --- a/tests/test_ode.py +++ b/tests/test_ode.py @@ -23,6 +23,7 @@ class Test_ODE: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): cls.problem = Explicit_Problem(y0=4.0) cls.simulator = ODE(cls.problem) diff --git a/tests/test_solvers.py b/tests/test_solvers.py index 88777fca..05691799 100644 --- a/tests/test_solvers.py +++ b/tests/test_solvers.py @@ -34,6 +34,7 @@ def handle_event(solver, event_info): class Test_Solvers: @classmethod + @pytest.fixture(autouse=True) def setup_class(cls): cls.problem = Implicit_Problem(res, [1.0], [-1.0]) cls.problem.state_events = state_events @@ -49,7 +50,7 @@ def test_radau5dae_state_events(self): t,y,yd = solver.simulate(2,33) - assert float(y[-1]) == pytest.approx(0.135, rel = 1e-3) + assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3) @testattr(stddist = True) def test_dopri5_state_events(self): @@ -57,7 +58,7 @@ def test_dopri5_state_events(self): t,y = solver.simulate(2,33) - assert float(y[-1]) == pytest.approx(0.135, rel = 1e-3) + assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3) @testattr(stddist = True) def test_rodasode_state_events(self): @@ -65,4 +66,4 @@ def test_rodasode_state_events(self): t,y = solver.simulate(2,33) - assert float(y[-1]) == pytest.approx(0.135, rel = 1e-3) + assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3)