|
| 1 | +import pytest |
| 2 | +import sys |
| 3 | +import os |
| 4 | + |
| 5 | +# Add the src directory to the path so we can import the modules |
| 6 | +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src")) |
| 7 | + |
| 8 | +from render.render import RenderHelper |
| 9 | + |
| 10 | + |
| 11 | +class TestMoonPhase: |
| 12 | + """Test suite for moon phase calculations.""" |
| 13 | + |
| 14 | + @pytest.mark.parametrize( |
| 15 | + "value,expected", |
| 16 | + [ |
| 17 | + (0.0, "wi-moon-new"), |
| 18 | + (0.25, "wi-moon-first-quarter"), |
| 19 | + (0.5, "wi-moon-full"), |
| 20 | + (0.75, "wi-moon-third-quarter"), |
| 21 | + (1.0, "wi-moon-new"), |
| 22 | + ] |
| 23 | + ) |
| 24 | + def test_wi_moon_phase_boundary_values(self, value, expected): |
| 25 | + """Test moon phase with exact boundary values between phases.""" |
| 26 | + result = RenderHelper.wi_moon_phase(value) |
| 27 | + assert result == expected |
| 28 | + |
| 29 | + @pytest.mark.parametrize( |
| 30 | + "value,expected", |
| 31 | + [ |
| 32 | + # Test values very close to 0 |
| 33 | + (0.001, "wi-moon-waxing-crescent-0"), |
| 34 | + (0.01, "wi-moon-waxing-crescent-0"), |
| 35 | + # Test values very close to 0.25 |
| 36 | + (0.249, "wi-moon-waxing-crescent-5"), |
| 37 | + (0.251, "wi-moon-waxing-gibbous-1"), |
| 38 | + # Test values very close to 0.5 |
| 39 | + (0.499, "wi-moon-waxing-gibbous-6"), |
| 40 | + (0.501, "wi-moon-waning-gibbous-1"), |
| 41 | + # Test values very close to 0.75 |
| 42 | + (0.749, "wi-moon-waning-gibbous-6"), |
| 43 | + (0.751, "wi-moon-waning-crescent-1"), |
| 44 | + # Test values very close to 1.0 |
| 45 | + (0.999, "wi-moon-waning-crescent-6"), |
| 46 | + ] |
| 47 | + ) |
| 48 | + def test_wi_moon_phase_very_small_increments(self, value, expected): |
| 49 | + """Test moon phase with very small increments to verify calculation precision.""" |
| 50 | + result = RenderHelper.wi_moon_phase(value) |
| 51 | + assert result == expected |
| 52 | + |
| 53 | + @pytest.mark.parametrize("i", range(6)) |
| 54 | + def test_wi_moon_phase_all_crescent_numbers(self, i): |
| 55 | + """Test that all waxing crescent phases produce valid numbers 0-5.""" |
| 56 | + # Calculate a value that should produce index i |
| 57 | + value = (i + 0.5) * 0.25 / 6 # Add 0.5 to target middle of range |
| 58 | + result = RenderHelper.wi_moon_phase(value) |
| 59 | + expected_suffix = str(i) |
| 60 | + assert result == f"wi-moon-waxing-crescent-{expected_suffix}" |
| 61 | + |
| 62 | + @pytest.mark.parametrize( |
| 63 | + "value,expected_num", |
| 64 | + [ |
| 65 | + # Test waxing gibbous (0.25 < value < 0.5) |
| 66 | + (0.26, 1), # Just after 0.25 |
| 67 | + (0.30, 2), # Early waxing gibbous |
| 68 | + (0.35, 3), # Mid waxing gibbous |
| 69 | + (0.40, 4), # Late waxing gibbous |
| 70 | + (0.45, 5), # Very late waxing gibbous |
| 71 | + (0.49, 6), # Just before full |
| 72 | + # Test waning gibbous (0.5 < value < 0.75) |
| 73 | + (0.51, 1), # Just after full |
| 74 | + (0.55, 2), # Early waning gibbous |
| 75 | + (0.60, 3), # Mid waning gibbous |
| 76 | + (0.65, 4), # Late waning gibbous |
| 77 | + (0.70, 5), # Very late waning gibbous |
| 78 | + (0.74, 6), # Just before third quarter |
| 79 | + ] |
| 80 | + ) |
| 81 | + def test_wi_moon_phase_all_gibbous_numbers(self, value, expected_num): |
| 82 | + """Test that all gibbous phases produce valid numbers 1-6.""" |
| 83 | + result = RenderHelper.wi_moon_phase(value) |
| 84 | + if value < 0.5: |
| 85 | + assert result == f"wi-moon-waxing-gibbous-{expected_num}" |
| 86 | + else: |
| 87 | + assert result == f"wi-moon-waning-gibbous-{expected_num}" |
| 88 | + |
| 89 | + @pytest.mark.parametrize( |
| 90 | + "value,expected", |
| 91 | + [ |
| 92 | + (0.125, "wi-moon-waxing-crescent-3"), # 1/8 |
| 93 | + (0.375, "wi-moon-waxing-gibbous-4"), # 3/8 |
| 94 | + (0.625, "wi-moon-waning-gibbous-4"), # 5/8 |
| 95 | + (0.875, "wi-moon-waning-crescent-4"), # 7/8 |
| 96 | + ] |
| 97 | + ) |
| 98 | + def test_wi_moon_phase_mathematical_precision(self, value, expected): |
| 99 | + """Test moon phase calculation with mathematically precise values.""" |
| 100 | + result = RenderHelper.wi_moon_phase(value) |
| 101 | + assert result == expected |
0 commit comments