from __future__ import annotations import unittest from PythonModels.components.amesim_pneumatic import ( AmesimPneumaticOrifice, AmesimPneumaticVolume, AmesimVariablePneumaticVolume, ) from PythonModels.systems.test_mql import GLOBAL_PARAMETERS, SUBMODEL_COUNTS, TestMqlSystem class TestMqlStructuralTest(unittest.TestCase): def test_snapshot_matches_amesim_archive_metadata(self) -> None: snapshot = TestMqlSystem().snapshot() self.assertEqual(snapshot.model_name, "test_mql") self.assertEqual(snapshot.component_count, 117) self.assertEqual(snapshot.connection_count, 84) self.assertEqual(snapshot.continuous_state_count, 132) self.assertEqual(snapshot.discrete_state_count, 24) self.assertEqual(snapshot.global_parameters["P0"], "153") self.assertEqual(snapshot.global_parameters["cf"], "0.45") def test_network_preserves_component_and_connection_counts(self) -> None: system = TestMqlSystem() self.assertEqual(len(system.network.components), 117) self.assertEqual(len(system.network.connections), 84) self.assertIn("pn_brp2_8", system.network.components) self.assertIn("pn_gas_data", system.network.components) def test_network_uses_typed_pneumatic_components_where_available(self) -> None: system = TestMqlSystem() self.assertEqual(system.typed_pneumatic_component_count, 28) self.assertIsInstance( system.network.components["pn_general_chamber"], AmesimPneumaticVolume, ) self.assertIsInstance( system.network.components["pn_c1_8"], AmesimVariablePneumaticVolume, ) self.assertIsInstance( system.network.components["pn_orifice_18"], AmesimPneumaticOrifice, ) self.assertIsInstance( system.network.components["pn_morifice_11"], AmesimPneumaticOrifice, ) self.assertEqual(len(system.pneumatic_state_vector()), 24) def test_can_build_pneumatic_branch_closure_from_typed_components(self) -> None: system = TestMqlSystem() closure = system.pneumatic_branch_closure( name="typed_branch", upstream_volume_alias="pn_general_chamber", orifice_alias="pn_orifice_18", downstream_volume_alias="pn_c1_8", ) snapshot = closure.snapshot() self.assertGreater(snapshot.flow, 0.0) self.assertIs( closure.components.upstream_volume, system.network.components["pn_general_chamber"], ) self.assertIs( closure.components.orifice, system.network.components["pn_orifice_18"], ) self.assertIs( closure.components.downstream_volume, system.network.components["pn_c1_8"], ) self.assertAlmostEqual( closure.components.upstream_volume.port_a.m_flow, -snapshot.flow, ) self.assertAlmostEqual( closure.components.downstream_volume.port_a.m_flow, snapshot.flow, ) def test_pneumatic_branch_closure_rejects_structural_components(self) -> None: system = TestMqlSystem() with self.assertRaises(TypeError): system.pneumatic_branch_closure( name="invalid_branch", upstream_volume_alias="pn_brp2_8", orifice_alias="pn_orifice_18", downstream_volume_alias="pn_c1_8", ) def test_submodel_counts_keep_key_amesim_families(self) -> None: self.assertEqual(SUBMODEL_COUNTS["PNRP17"], 8) self.assertEqual(SUBMODEL_COUNTS["PNCH012"], 8) self.assertEqual(SUBMODEL_COUNTS["PNOR001"], 8) self.assertEqual(SUBMODEL_COUNTS["PNVO001"], 8) self.assertEqual(SUBMODEL_COUNTS["PNGD00"], 1) self.assertEqual(GLOBAL_PARAMETERS["V"], "15") def test_structural_simulation_shape(self) -> None: result = TestMqlSystem().simulate() self.assertEqual(len(result.t), 101) self.assertEqual(len(result.y), 132) self.assertEqual(result.series["component_count"][0], 117.0) self.assertEqual(result.series["connection_count"][0], 84.0) if __name__ == "__main__": unittest.main()