77class TestMorphSqueeze :
88 @pytest .fixture
99 def setup (self ):
10- # Create a sine-wave for testing
11- self .x_morph = np .linspace (0 , 2 * np . pi , 1000 )
10+ # Create data for testing
11+ self .x_morph = np .linspace (0 , 10 , 1000 )
1212 self .y_morph = np .sin (self .x_morph )
1313 self .x_target = self .x_morph .copy ()
1414 self .y_target = self .y_morph .copy ()
1515 return
1616
1717 def test_no_squeeze (self , setup ):
18- """When squeeze is zero, the input should be unchanged."""
18+ """When both squeeze are zero, the input should be unchanged."""
1919 morph = MorphSqueeze ()
20- morph .squeeze = 0.0
20+ morph .squeeze_1 = 0.0
21+ morph .squeeze_2 = 0.0
2122
2223 x_morph , y_morph , x_target , y_target = morph (
2324 self .x_morph , self .y_morph , self .x_target , self .y_target
@@ -34,7 +35,9 @@ def test_morph_with_squeeze(self, setup):
3435 """Test that with a non-zero squeeze,
3536 x_morph is transformed non-linearly."""
3637 morph = MorphSqueeze ()
37- morph .squeeze = 0.7
38+ morph .squeeze_1 = - 0.07
39+ morph .squeeze_2 = 0.1
40+
3841 x_new , y_new , x_target , y_target = morph (
3942 self .x_morph , self .y_morph , self .x_target , self .y_target
4043 )
@@ -43,9 +46,14 @@ def test_morph_with_squeeze(self, setup):
4346 assert np .allclose (self .y_target , y_target )
4447
4548 # For this test, we expect:
46- # x_new = x_morph + squeeze_factor * sin(x_morph)
47- expected_x = self .x_morph + morph .squeeze * np .sin (self .x_morph )
48- expected_y = np .sin (expected_x )
49+ # x_new = x_morph + squeeze_1 * x_morph ** 2 +
50+ # squeeze_2 * x_morph ** 3
51+ expected_x = (
52+ self .x_morph
53+ + morph .squeeze_1 * self .x_morph ** 2
54+ + morph .squeeze_2 * self .x_morph ** 3
55+ )
56+ expected_y = np .interp (expected_x , self .x_morph , self .y_morph )
4957
5058 # Allow for some tolerance because of numerical interpolation if used
5159 res = sum (np .fabs (expected_y - y_new ))
0 commit comments