-
-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathtest_monte_carlo.py
More file actions
89 lines (70 loc) · 3.24 KB
/
Copy pathtest_monte_carlo.py
File metadata and controls
89 lines (70 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import matplotlib as plt
import numpy as np
plt.rcParams.update({"figure.max_open_warning": 0})
def test_stochastic_environment_create_object_with_wind_x(stochastic_environment):
"""Tests the stochastic environment object by checking if the wind velocity
can be generated properly. The goal is to check if the create_object()
method is being called without any problems.
Parameters
----------
stochastic_environment : StochasticEnvironment
The stochastic environment object, this is a pytest fixture.
"""
wind_x_at_1000m = []
for _ in range(10):
random_env = stochastic_environment.create_object()
wind_x_at_1000m.append(random_env.wind_velocity_x(1000))
assert np.isclose(np.mean(wind_x_at_1000m), 0, atol=0.1)
assert np.isclose(np.std(wind_x_at_1000m), 0, atol=0.1)
# TODO: add a new test for the special case of ensemble member
def test_monte_carlo_plots_all_with_filename(monte_carlo_calisto_pre_loaded, tmp_path):
"""Tests the all method of the MonteCarlo plots with filename parameter.
Parameters
----------
monte_carlo_calisto_pre_loaded : MonteCarlo
A MonteCarlo object with pre-loaded results, this is a pytest fixture.
tmp_path : Path
Temporary directory path for saving test files.
"""
# Test without filename (should work as before)
result = monte_carlo_calisto_pre_loaded.plots.all()
assert result is None
# Test with filename - save to temporary directory
filename = tmp_path / "test_monte_carlo_plot.png"
result = monte_carlo_calisto_pre_loaded.plots.all(filename=str(filename))
assert result is None
# Test with specific keys and filename
filename_apogee = tmp_path / "test_apogee_plot.png"
result = monte_carlo_calisto_pre_loaded.plots.all(
keys="apogee", filename=str(filename_apogee)
)
assert result is None
def test_stochastic_solid_motor_create_object_with_impulse(stochastic_solid_motor):
"""Tests the stochastic solid motor object by checking if the total impulse
can be generated properly. The goal is to check if the create_object()
method is being called without any problems.
Parameters
----------
stochastic_solid_motor : StochasticSolidMotor
The stochastic solid motor object, this is a pytest fixture.
"""
total_impulse = [
stochastic_solid_motor.create_object().total_impulse for _ in range(200)
]
assert np.isclose(np.mean(total_impulse), 6500, rtol=0.3)
assert np.isclose(np.std(total_impulse), 1000, rtol=0.4)
def test_stochastic_calisto_create_object_with_static_margin(stochastic_calisto):
"""Tests the stochastic calisto object by checking if the static margin
can be generated properly. The goal is to check if the create_object()
method is being called without any problems.
Parameters
----------
stochastic_calisto : StochasticCalisto
The stochastic calisto object, this is a pytest fixture.
"""
all_margins = []
for _ in range(10):
random_rocket = stochastic_calisto.create_object()
all_margins.append(random_rocket.static_margin(0))
assert np.isclose(np.mean(all_margins), 2.2625350013000434, rtol=0.15)
assert np.isclose(np.std(all_margins), 0.1, atol=0.2)