diff --git a/tests/test_theme_nerv_fx.py b/tests/test_theme_nerv_fx.py new file mode 100644 index 0000000..ea3bf6a --- /dev/null +++ b/tests/test_theme_nerv_fx.py @@ -0,0 +1,56 @@ +import unittest +from unittest.mock import MagicMock, patch +import math +from src.theme_nerv_fx import ScanlineOverlay, StatusFlicker + +class TestThemeNervFx(unittest.TestCase): + @patch("src.theme_nerv_fx.imgui") + def test_scanline_overlay_render(self, mock_imgui): + # Setup + mock_draw_list = MagicMock() + mock_imgui.get_foreground_draw_list.return_value = mock_draw_list + mock_imgui.get_color_u32.return_value = 0x12345678 + + overlay = ScanlineOverlay() + width, height = 100.0, 10.0 + + # Act + overlay.render(width, height) + + # Assert + mock_imgui.get_foreground_draw_list.assert_called_once() + # height is 10, range(0, 10, 2) is [0, 2, 4, 6, 8] -> 5 calls + self.assertEqual(mock_draw_list.add_line.call_count, 5) + + # Verify some calls + mock_draw_list.add_line.assert_any_call((0.0, 0.0), (100.0, 0.0), 0x12345678, 1.0) + mock_draw_list.add_line.assert_any_call((0.0, 8.0), (100.0, 8.0), 0x12345678, 1.0) + + @patch("src.theme_nerv_fx.time") + def test_status_flicker_get_alpha(self, mock_time): + flicker = StatusFlicker() + + # Test at multiple points in time to ensure range [0.7, 1.0] + # sin(0) = 0 -> 0.85 + mock_time.time.return_value = 0.0 + self.assertAlmostEqual(flicker.get_alpha(), 0.85) + + # sin(pi/2) = 1 -> 1.0 + # time * 20.0 = pi/2 -> time = pi/40 + mock_time.time.return_value = math.pi / 40.0 + self.assertAlmostEqual(flicker.get_alpha(), 1.0) + + # sin(3pi/2) = -1 -> 0.7 + # time * 20.0 = 3pi/2 -> time = 3pi/40 + mock_time.time.return_value = 3 * math.pi / 40.0 + self.assertAlmostEqual(flicker.get_alpha(), 0.7) + + # Verify range for many samples + for i in range(100): + mock_time.time.return_value = i * 0.1 + alpha = flicker.get_alpha() + self.assertGreaterEqual(alpha, 0.7) + self.assertLessEqual(alpha, 1.0) + +if __name__ == "__main__": + unittest.main()