From 8b94969bb65c910aa581299a5422e1feafa8534e Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Wed, 15 Oct 2025 14:23:40 +0200 Subject: [PATCH] aggiunti altri test --- Temp/scenario_init_20251015_141354_896.txt | 4 ++ Temp/scenario_init_20251015_141438_856.txt | 4 ++ Temp/scenario_init_20251015_141624_679.txt | 4 ++ Temp/scenario_init_20251015_141748_634.txt | 4 ++ Temp/scenario_init_20251015_141841_099.txt | 4 ++ Temp/scenario_init_20251015_141914_012.txt | 4 ++ tests/core/test_simulation_engine.py | 45 +++++++++++++++++ tests/gui/test_target_list_frame.py | 57 ++++++++++++++++++++++ 8 files changed, 126 insertions(+) create mode 100644 Temp/scenario_init_20251015_141354_896.txt create mode 100644 Temp/scenario_init_20251015_141438_856.txt create mode 100644 Temp/scenario_init_20251015_141624_679.txt create mode 100644 Temp/scenario_init_20251015_141748_634.txt create mode 100644 Temp/scenario_init_20251015_141841_099.txt create mode 100644 Temp/scenario_init_20251015_141914_012.txt diff --git a/Temp/scenario_init_20251015_141354_896.txt b/Temp/scenario_init_20251015_141354_896.txt new file mode 100644 index 0000000..4533061 --- /dev/null +++ b/Temp/scenario_init_20251015_141354_896.txt @@ -0,0 +1,4 @@ +pause +aclatch +acunlatch +continue diff --git a/Temp/scenario_init_20251015_141438_856.txt b/Temp/scenario_init_20251015_141438_856.txt new file mode 100644 index 0000000..4533061 --- /dev/null +++ b/Temp/scenario_init_20251015_141438_856.txt @@ -0,0 +1,4 @@ +pause +aclatch +acunlatch +continue diff --git a/Temp/scenario_init_20251015_141624_679.txt b/Temp/scenario_init_20251015_141624_679.txt new file mode 100644 index 0000000..4533061 --- /dev/null +++ b/Temp/scenario_init_20251015_141624_679.txt @@ -0,0 +1,4 @@ +pause +aclatch +acunlatch +continue diff --git a/Temp/scenario_init_20251015_141748_634.txt b/Temp/scenario_init_20251015_141748_634.txt new file mode 100644 index 0000000..4533061 --- /dev/null +++ b/Temp/scenario_init_20251015_141748_634.txt @@ -0,0 +1,4 @@ +pause +aclatch +acunlatch +continue diff --git a/Temp/scenario_init_20251015_141841_099.txt b/Temp/scenario_init_20251015_141841_099.txt new file mode 100644 index 0000000..4533061 --- /dev/null +++ b/Temp/scenario_init_20251015_141841_099.txt @@ -0,0 +1,4 @@ +pause +aclatch +acunlatch +continue diff --git a/Temp/scenario_init_20251015_141914_012.txt b/Temp/scenario_init_20251015_141914_012.txt new file mode 100644 index 0000000..4533061 --- /dev/null +++ b/Temp/scenario_init_20251015_141914_012.txt @@ -0,0 +1,4 @@ +pause +aclatch +acunlatch +continue diff --git a/tests/core/test_simulation_engine.py b/tests/core/test_simulation_engine.py index d1e193a..da1708f 100644 --- a/tests/core/test_simulation_engine.py +++ b/tests/core/test_simulation_engine.py @@ -42,3 +42,48 @@ def test_simulation_engine_start_stop(fake_communicator, fake_update_queue): assert engine.is_alive() engine._stop_event.set() engine.join(timeout=1) + + +def test_set_time_multiplier(fake_communicator, fake_update_queue): + engine = SimulationEngine(fake_communicator, fake_update_queue) + engine.set_time_multiplier(2.5) + assert engine.time_multiplier == 2.5 + + +def test_set_update_interval(fake_communicator, fake_update_queue): + engine = SimulationEngine(fake_communicator, fake_update_queue) + engine.set_update_interval(0.5) + assert engine.update_interval_s == 0.5 + + +def test_pause_resume(fake_communicator, fake_update_queue): + engine = SimulationEngine(fake_communicator, fake_update_queue) + engine.pause() + assert engine._is_paused is True + engine.resume() + assert engine._is_paused is False + + +def test_stop(fake_communicator, fake_update_queue): + engine = SimulationEngine(fake_communicator, fake_update_queue) + engine.start() + engine.stop() + assert not engine.is_alive() or not engine.is_running() + + +def test_set_simulation_time(fake_communicator, fake_update_queue): + engine = SimulationEngine(fake_communicator, fake_update_queue) + scenario = Scenario(name="JumpScenario") + t = Target(target_id=2, trajectory=[Waypoint(maneuver_type=ManeuverType.FLY_TO_POINT)]) + scenario.add_target(t) + engine.load_scenario(scenario) + engine.set_simulation_time(42.0) + assert getattr(t, "_sim_time_s", None) == 42.0 + + +def test_is_running_flag(fake_communicator, fake_update_queue): + engine = SimulationEngine(fake_communicator, fake_update_queue) + assert not engine.is_running() + engine.start() + assert engine.is_running() + engine.stop() diff --git a/tests/gui/test_target_list_frame.py b/tests/gui/test_target_list_frame.py index a5ef59b..6718dee 100644 --- a/tests/gui/test_target_list_frame.py +++ b/tests/gui/test_target_list_frame.py @@ -8,3 +8,60 @@ def test_target_list_frame_init(): frame = TargetListFrame(root) assert frame is not None root.destroy() + + +def test_get_targets_returns_cache(): + root = tk.Tk() + frame = TargetListFrame(root) + frame.targets_cache = ["dummy_target"] + assert frame.get_targets() == ["dummy_target"] + root.destroy() + + +def test_update_target_list_updates_cache(): + root = tk.Tk() + frame = TargetListFrame(root) + from target_simulator.core.models import Target + t = Target(target_id=1) + t.current_range_nm = 10.0 + t.current_azimuth_deg = 45.0 + t.current_velocity_fps = 100.0 + t.current_heading_deg = 90.0 + t.current_altitude_ft = 5000.0 + frame.update_target_list([t]) + assert frame.targets_cache == [t] + root.destroy() + + +def test_targets_changed_callback_called(): + root = tk.Tk() + called = {} + def cb(targets): + called["ok"] = True + frame = TargetListFrame(root, targets_changed_callback=cb) + frame.targets_cache = [] + from target_simulator.core.models import Target + t = Target(target_id=2) + t.current_range_nm = 20.0 + t.current_azimuth_deg = 90.0 + t.current_velocity_fps = 200.0 + t.current_heading_deg = 180.0 + t.current_altitude_ft = 10000.0 + frame.update_target_list([t]) + if frame.targets_changed_callback: + frame.targets_changed_callback(frame.targets_cache) + assert called.get("ok") + root.destroy() + + +def test_on_remove_click_no_selection(monkeypatch): + root = tk.Tk() + frame = TargetListFrame(root) + frame.tree.focus = lambda: "" + called = {} + def warn(title, msg, parent=None): + called["warn"] = True + monkeypatch.setattr("tkinter.messagebox.showwarning", warn) + frame._on_remove_click() + assert called.get("warn") + root.destroy()