Skip to content

Commit 85a7e30

Browse files
committed
Initial test for ISAtmosphere block
1 parent f6474c4 commit 85a7e30

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

tests/atmosphere/__init__.py

Whitespace-only changes.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
########################################################################################
2+
##
3+
## TESTS FOR
4+
## 'atmosphere.international_standard_atmosphere.py'
5+
##
6+
########################################################################################
7+
8+
# IMPORTS ==============================================================================
9+
10+
import unittest
11+
from pathsim_flight.atmosphere import ISAtmosphere
12+
13+
# TESTS ================================================================================
14+
15+
class TestISAtmosphere(unittest.TestCase):
16+
"""Test the ISAAtmosphere block."""
17+
18+
def test_standard_day_sealevel_constants(self):
19+
"""Test standard day sea level constants"""
20+
isa = ISAtmosphere()
21+
self.assertEqual(isa.StdSL_pressure, 101325)
22+
self.assertEqual(isa.StdSL_speed_of_sound, 340.294)
23+
24+
def test_band_boundaries(self):
25+
"""Test custom initialization with user-specified groups."""
26+
isa = ISAtmosphere()
27+
28+
# ISA band boundaries, base temperatures, and base pressures (from standard day) for 0-71 km altitude
29+
bands = [
30+
[0, 288.15, 101325.0],
31+
[11000, 216.65, 22632.0],
32+
[20000, 216.65, 5474.9],
33+
[32000, 228.65, 868.02],
34+
[47000, 270.65, 110.91],
35+
[51000, 270.65, 66.939],
36+
[71000, 214.65, 3.9564]
37+
]
38+
39+
for band_info in bands:
40+
isa.inputs[0] = isa.geometric_altitude(band_info[0]) # altitude
41+
isa.inputs[1] = 0 # temp deviation
42+
43+
isa.update(None)
44+
45+
print(f"Testing altitude {band_info[0]} m: pressure={isa.outputs[0]} Pa, temperature={isa.outputs[2]} K")
46+
47+
print(isa.outputs[0], band_info[2])
48+
print(isa.outputs[2], band_info[1])
49+
50+
self.assertAlmostEqual(isa.outputs[0], band_info[2], places=1) # pressure
51+
self.assertAlmostEqual(isa.outputs[2], band_info[1], places=1) # temperature
52+
53+
def test_input_validation(self):
54+
"""Test input validation."""
55+
isa = ISAtmosphere()
56+
57+
# Altitudes out of bounds of the International Standard Atmosphere should raise IndexError
58+
with self.assertRaises(IndexError):
59+
isa._eval(-100)
60+
with self.assertRaises(IndexError):
61+
isa._eval(90000)
62+
63+
def test_port_labels(self):
64+
"""Test port label definitions."""
65+
self.assertEqual(ISAtmosphere.input_port_labels["altitude"], 0)
66+
self.assertEqual(ISAtmosphere.input_port_labels["temp_deviation"], 1)
67+
self.assertEqual(ISAtmosphere.output_port_labels["pressure"], 0)
68+
self.assertEqual(ISAtmosphere.output_port_labels["density"], 1)
69+
self.assertEqual(ISAtmosphere.output_port_labels["temperature"], 2)
70+
self.assertEqual(ISAtmosphere.output_port_labels["speed_of_sound"], 3)
71+
72+
def test_temp_deviation(self):
73+
"""Check that temperature deviation from standard day behaves as expected."""
74+
75+
altitudes = [0, 5_000, 15_000, 25_000, 35_000, 49_000, 65_000, 75_000]
76+
isa = ISAtmosphere()
77+
78+
for altitude in altitudes:
79+
# No temperature deviation (standard day)
80+
isa.inputs[0] = altitude
81+
isa.inputs[1] = 0
82+
isa.update(None)
83+
pressure_std_day = isa.outputs[0]
84+
density_std_day = isa.outputs[1]
85+
temperature_std_day = isa.outputs[2]
86+
87+
# Positive temperature deviation of +10K
88+
isa.inputs[0] = altitude
89+
isa.inputs[1] = 10
90+
isa.update(None)
91+
pressure_pos_dev = isa.outputs[0]
92+
density_pos_dev = isa.outputs[1]
93+
temperature_pos_dev = isa.outputs[2]
94+
95+
# Negative temperature deviation of -10K
96+
isa.inputs[0] = altitude
97+
isa.inputs[1] = -10
98+
isa.update(None)
99+
pressure_neg_dev = isa.outputs[0]
100+
density_neg_dev = isa.outputs[1]
101+
temperature_neg_dev = isa.outputs[2]
102+
103+
# Checks
104+
self.assertAlmostEqual(temperature_pos_dev, temperature_std_day + 10)
105+
self.assertAlmostEqual(temperature_neg_dev, temperature_std_day - 10)
106+
107+
self.assertAlmostEqual(pressure_pos_dev, pressure_std_day)
108+
self.assertAlmostEqual(pressure_neg_dev, pressure_std_day)
109+
110+
self.assertGreater(density_std_day, density_pos_dev)
111+
self.assertGreater(density_neg_dev, density_std_day)
112+
113+
114+
# RUN TESTS LOCALLY ====================================================================
115+
116+
if __name__ == '__main__':
117+
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)