@@ -87,15 +87,44 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs):
8787 assert np .allclose (y_target_actual , y_target )
8888
8989
90- def test_morphsqueeze_extrapolate ():
90+ @pytest .mark .parametrize (
91+ "squeeze_coeffs, wmsg_gen" ,
92+ [
93+ # extrapolate below
94+ (
95+ {"a0" : 0.01 },
96+ lambda x : (
97+ "Warning: points with grid value below "
98+ f"{ x [0 ]} will be extrapolated."
99+ ),
100+ ),
101+ # extrapolate above
102+ (
103+ {"a0" : - 0.01 },
104+ lambda x : (
105+ "Warning: points with grid value above "
106+ f"{ x [1 ]} will be extrapolated."
107+ ),
108+ ),
109+ # extrapolate below and above
110+ (
111+ {"a0" : 0.01 , "a1" : - 0.002 },
112+ lambda x : (
113+ "Warning: points with grid value below "
114+ f"{ x [0 ]} and above { x [1 ]} will be "
115+ "extrapolated."
116+ ),
117+ ),
118+ ],
119+ )
120+ def test_morphsqueeze_extrapolate (squeeze_coeffs , wmsg_gen ):
91121 x_morph = np .linspace (0 , 10 , 101 )
92122 y_morph = np .sin (x_morph )
93123 x_target = x_morph
94124 y_target = y_morph
95- squeeze_coeff = {"a0" : 0.01 , "a1" : - 0.0005 , "a2" : - 0.0005 , "a3" : - 1e-6 }
96125 morph = MorphSqueeze ()
97- morph .squeeze = squeeze_coeff
98- coeffs = [squeeze_coeff [f"a{ i } " ] for i in range (len (squeeze_coeff ))]
126+ morph .squeeze = squeeze_coeffs
127+ coeffs = [squeeze_coeffs [f"a{ i } " ] for i in range (len (squeeze_coeffs ))]
99128 squeeze_polynomial = Polynomial (coeffs )
100129 x_squeezed = x_morph + squeeze_polynomial (x_morph )
101130 with pytest .warns () as w :
@@ -105,10 +134,5 @@ def test_morphsqueeze_extrapolate():
105134 assert len (w ) == 1
106135 assert w [0 ].category is UserWarning
107136 actual_wmsg = str (w [0 ].message )
108- expected_wmsg = (
109- "\n Extrapolating the morphed function via CubicSpline:\n "
110- f"Obtaining grid points between { x_morph [0 ]} and { x_morph [- 1 ]} .\n "
111- f"Points below { x_squeezed [0 ]} and "
112- f"above { x_squeezed [- 1 ]} will be extrapolated."
113- )
137+ expected_wmsg = wmsg_gen ([min (x_squeezed ), max (x_squeezed )])
114138 assert actual_wmsg == expected_wmsg
0 commit comments