Skip to content

Commit

Permalink
Comment out tests that check the slave positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorgelmh committed Nov 4, 2024
1 parent 6914616 commit 0cce14b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
1 change: 0 additions & 1 deletion tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def test_cases():
msg = "'restitutionAndGravity' should exist within the sub-hierarchy of 'restitution_case'"
assert restitution_case is not None and restitution_case.case_by_name("restitutionAndGravity") is not None, msg
# variables (aliases)
assert cases.variables["h"]["model"] == 0
assert cases.variables["h"]["instances"] == ("bb",)
assert cases.variables["h"]["variables"] == (1,)
assert cases.variables["h"]["description"] == "Position (z) of the ball"
Expand Down
14 changes: 9 additions & 5 deletions tests/test_run_bouncingball0.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ def test_step_by_step_interface():
path = Path(Path(__file__).parent, "data/BouncingBall0/OspSystemStructure.xml")
assert path.exists(), "System structure file not found"
sim = SimulatorInterface(path)
assert sim.components["bb"] == 0
print(f"Variables: {sim.get_variables( 0, as_numbers = False)}")
assert sim.get_variables(0)["e"] == {"reference": 6, "type": 0, "causality": 1, "variability": 2}
# Commented out as order of variables and models are not guaranteed in different OS
# assert sim.components["bb"] == 0
# print(f"Variables: {sim.get_variables( 0, as_numbers = False)}")
# assert sim.get_variables(0)["e"] == {"reference": 6, "type": 0, "causality": 1, "variability": 2}
sim.set_initial(0, 0, 6, 0.35)
for t in np.linspace(1, 1e9, 1):
sim.simulator.simulate_until(t)
Expand Down Expand Up @@ -170,8 +171,10 @@ def test_run_cases():
assert case.special == {"startTime": 0.0, "stopTime": 3, "stepSize": 0.01}
case.run("results_base")
res = cases.case_by_name("base").res.res
inspect = cases.case_by_name("base").res.inspect()
assert inspect["bb.h"] == {
"""
Cannot be tested in CI as order of variables and models are not guaranteed in different OSs
inspect = cases.case_by_name("base").res.inspect()
assert inspect["bb.h"] == {
"len": 301,
"range": [0.0, 3.0],
"info": {
Expand All @@ -184,6 +187,7 @@ def test_run_cases():
"variability": 4,
},
}
"""
# key results data for base case
h0 = res.jspath("$.['0'].bb.h")
t0 = sqrt(2 * h0 / 9.81) # half-period time with full restitution
Expand Down
18 changes: 8 additions & 10 deletions tests/test_simulator_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ def test_pytype():
def test_component_variable_name():
path = Path(Path(__file__).parent, "data/BouncingBall0/OspSystemStructure.xml")
system = SimulatorInterface(str(path), name="BouncingBall")
assert 1 == system.simulator.slave_index_from_instance_name("bb")
assert 0 == system.simulator.slave_index_from_instance_name("bb2")
assert 2 == system.simulator.slave_index_from_instance_name("bb3")
assert system.components["bb"] == 0, f"Error in unique model index. Found {system.components['bb']}"
"""
Slave order is not guaranteed in different OS
assert 1 == system.simulator.slave_index_from_instance_name("bb")
assert 0 == system.simulator.slave_index_from_instance_name("bb2")
assert 2 == system.simulator.slave_index_from_instance_name("bb3")
assert system.components["bb"] == 0, f"Error in unique model index. Found {system.components['bb']}"
"""
assert system.variable_name_from_ref("bb", 0) == "time"
assert system.variable_name_from_ref("bb", 1) == "h"
assert system.variable_name_from_ref("bb", 2) == "der(h)"
Expand Down Expand Up @@ -71,7 +74,7 @@ def test_simulator_from_system_structure():
system = SimulatorInterface(str(path), name="BouncingBall")
assert system.name == "BouncingBall", f"System.name should be BouncingBall. Found {system.name}"
assert "bb" in system.components, f"Instance name 'bb' expected. Found instances {system.components}"
assert system.get_models()[0] == 0, f"Component model {system.get_models()[0]}"
# assert system.get_models()[0] == 0, f"Component model {system.get_models()[0]}"
assert "bb" in system.get_components()


Expand Down Expand Up @@ -99,8 +102,6 @@ def test_simulator_instantiated():
)
# simulator.check_instances_variables()
assert len(simulator.components) == 3, "Three instantiated (identical) components"
assert simulator.components["bb"] == 0, f"... given a unique identifier {simulator.components['bb']}"
assert simulator.components["bb2"] == 0, f"... given a unique identifier {simulator.components['bb2']}"
variables = simulator.get_variables("bb")
assert variables["g"] == {"reference": 5, "type": 0, "causality": 1, "variability": 1}
assert simulator.allowed_action("set", "bb", "g", 0)
Expand All @@ -118,9 +119,6 @@ def test_simulator_instantiated():
assert not simulator.allowed_action("set", "bb", "v_min", 0), simulator.message
assert simulator.allowed_action("set", "bb", (1, 3), 0), simulator.message # combination of h,v
assert not simulator.allowed_action("set", "bb", (1, 3), 100), simulator.message # combination of h,v
assert simulator.get_variables(0) == simulator.get_variables("bb"), "Two ways of accessing variables"
assert simulator.get_variables(0, "h"), {"h": {"reference": 1, "type": 0, "causality": 2, "variability": 4}}
assert simulator.get_variables(0, 1), {"h": {"reference": 1, "type": 0, "causality": 2, "variability": 4}}


if __name__ == "__main__":
Expand Down

0 comments on commit 0cce14b

Please sign in to comment.