From 31103c62c355c1a077cf32416ecf646b22eb4ef1 Mon Sep 17 00:00:00 2001 From: Shisato Yano Date: Tue, 6 Oct 2026 01:07:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Run=20smoke=20tests=20for?= =?UTF-8?q?=20the=20simulation's=20frame=20count=20instead=20of=201000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In test mode GlobalXYVisualizer.draw() always ran 1000 frames, while the simulations only need span_sec / interval_sec + 1 frames (81-551). Use the same frame count as the animation so smoke tests stop doing 2-12x extra work. Closes #86 Co-Authored-By: Claude Opus 5.5 --- .../visualization/global_xy_visualizer.py | 2 +- test/test_global_xy_visualizer.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/test_global_xy_visualizer.py diff --git a/src/components/visualization/global_xy_visualizer.py b/src/components/visualization/global_xy_visualizer.py index f228789c..f64bfccc 100644 --- a/src/components/visualization/global_xy_visualizer.py +++ b/src/components/visualization/global_xy_visualizer.py @@ -105,4 +105,4 @@ def draw(self): print("Simulation finished!!") else: # only when executed as unit test - for i in range(1000): self.update(i, elems, axes) + for i in range(self.time_params.get_frame_num()): self.update(i, elems, axes) diff --git a/test/test_global_xy_visualizer.py b/test/test_global_xy_visualizer.py new file mode 100644 index 00000000..0771b3fa --- /dev/null +++ b/test/test_global_xy_visualizer.py @@ -0,0 +1,44 @@ +""" +Unit test of GlobalXYVisualizer + +Author: Shisato Yano +""" + +import matplotlib +matplotlib.use("Agg") + +import sys +from pathlib import Path + +sys.path.append(str(Path(__file__).absolute().parent) + "/../src/components/visualization") +from global_xy_visualizer import GlobalXYVisualizer +from min_max import MinMax +from time_parameters import TimeParameters + + +class FakeObject: + """ + Object which only counts how many times it was updated + """ + + def __init__(self): + self.update_count = 0 + + def draw(self, axes, elems): + pass + + def update(self, time_s): + self.update_count += 1 + + +def test_draw_without_plot_runs_frame_num_frames(): + # smoke tests must run as many frames as the animation does, not a fixed number + time_params = TimeParameters(span_sec=5) + vis = GlobalXYVisualizer(MinMax(), MinMax(), time_params) + obj = FakeObject() + vis.add_object(obj) + vis.not_show_plot() + + vis.draw() + + assert obj.update_count == time_params.get_frame_num()