|
1 | 1 | import numpy as np |
2 | 2 | import pytest |
3 | 3 |
|
4 | | -# from diffpy.morph.morphs.morphfuncx import MorphFuncx |
5 | | -from diffpy.morph.morphs.morphfuncy import MorphFuncy |
| 4 | +from diffpy.morph.morphs.morphfuncx import MorphFuncx |
6 | 5 |
|
7 | 6 |
|
8 | | -def sine_function(x, y, amplitude, frequency): |
9 | | - return amplitude * np.sin(frequency * x) * y |
| 7 | +def x_exponential_function(x, y, x_amplitude, x_rate): |
| 8 | + return x_amplitude * np.exp(x_rate * x) |
10 | 9 |
|
11 | 10 |
|
12 | | -def exponential_decay_function(x, y, amplitude, decay_rate): |
13 | | - return amplitude * np.exp(-decay_rate * x) * y |
| 11 | +def x_linear_function(x, y, x_slope, x_intercept): |
| 12 | + return x_slope * x + x_intercept |
14 | 13 |
|
15 | 14 |
|
16 | | -def gaussian_function(x, y, amplitude, mean, sigma): |
17 | | - return amplitude * np.exp(-((x - mean) ** 2) / (2 * sigma**2)) * y |
| 15 | +def x_cubic_function(x, y, x_amplitude, x_shift): |
| 16 | + return x_amplitude * (x - x_shift) ** 3 |
18 | 17 |
|
19 | 18 |
|
20 | | -def polynomial_function(x, y, a, b, c): |
21 | | - return (a * x**2 + b * x + c) * y |
| 19 | +def x_arctan_function(x, y, x_amplitude, x_frequency): |
| 20 | + return x_amplitude * np.arctan(x_frequency * x) |
22 | 21 |
|
23 | 22 |
|
24 | | -def logarithmic_function(x, y, scale): |
25 | | - return scale * np.log(1 + x) * y |
| 23 | +funcx_test_suite = [ |
| 24 | + ( |
| 25 | + x_exponential_function, |
| 26 | + {"x_amplitude": 2, "x_rate": 5}, |
| 27 | + lambda x, y: 2 * np.exp(5 * x), |
| 28 | + ), |
| 29 | + ( |
| 30 | + x_linear_function, |
| 31 | + {"x_slope": 5, "x_intercept": 0.1}, |
| 32 | + lambda x, y: 5 * x + 0.1, |
| 33 | + ), |
| 34 | + ( |
| 35 | + x_cubic_function, |
| 36 | + {"x_amplitude": 2, "x_shift": 5}, |
| 37 | + lambda x, y: 2 * (x - 5) ** 3, |
| 38 | + ), |
| 39 | + ( |
| 40 | + x_arctan_function, |
| 41 | + {"x_amplitude": 4, "x_frequency": 2}, |
| 42 | + lambda x, y: 4 * np.arctan(2 * x), |
| 43 | + ), |
| 44 | +] |
26 | 45 |
|
27 | 46 |
|
28 | | -# FIXME: |
29 | 47 | @pytest.mark.parametrize( |
30 | 48 | "function, parameters, expected_function", |
31 | | - [ |
32 | | - ( |
33 | | - sine_function, |
34 | | - {"amplitude": 2, "frequency": 5}, |
35 | | - lambda x, y: 2 * np.sin(5 * x) * y, |
36 | | - ), |
37 | | - ( |
38 | | - exponential_decay_function, |
39 | | - {"amplitude": 5, "decay_rate": 0.1}, |
40 | | - lambda x, y: 5 * np.exp(-0.1 * x) * y, |
41 | | - ), |
42 | | - ( |
43 | | - gaussian_function, |
44 | | - {"amplitude": 1, "mean": 5, "sigma": 1}, |
45 | | - lambda x, y: np.exp(-((x - 5) ** 2) / (2 * 1**2)) * y, |
46 | | - ), |
47 | | - ( |
48 | | - polynomial_function, |
49 | | - {"a": 1, "b": 2, "c": 0}, |
50 | | - lambda x, y: (x**2 + 2 * x) * y, |
51 | | - ), |
52 | | - ( |
53 | | - logarithmic_function, |
54 | | - {"scale": 0.5}, |
55 | | - lambda x, y: 0.5 * np.log(1 + x) * y, |
56 | | - ), |
57 | | - ], |
| 49 | + funcx_test_suite, |
58 | 50 | ) |
59 | 51 | def test_funcy(function, parameters, expected_function): |
60 | 52 | x_morph = np.linspace(0, 10, 101) |
61 | 53 | y_morph = np.sin(x_morph) |
62 | 54 | x_target = x_morph.copy() |
63 | 55 | y_target = y_morph.copy() |
64 | | - x_morph_expected = x_morph |
65 | | - y_morph_expected = expected_function(x_morph, y_morph) |
66 | | - morph = MorphFuncy() |
67 | | - morph.funcy_function = function |
68 | | - morph.funcy = parameters |
| 56 | + x_morph_expected = expected_function(x_morph, y_morph) |
| 57 | + y_morph_expected = y_morph |
| 58 | + morph = MorphFuncx() |
| 59 | + morph.funcx_function = function |
| 60 | + morph.funcx = parameters |
69 | 61 | x_morph_actual, y_morph_actual, x_target_actual, y_target_actual = ( |
70 | 62 | morph.morph(x_morph, y_morph, x_target, y_target) |
71 | 63 | ) |
|
0 commit comments