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()