Files
Jyotisha/tests/test_kp_exact_angular_boundaries.py
T
jesse-uxGrok (agent loop)Cursor
b5eb72343a fix(kp): place exact angular boundaries on the opening subdivision
Upstream 8eec9a54. Floating accumulation and a 120-degree remainder put star, pada, and sub-lord on different sides of the same boundary. Random longitudes away from those boundaries are unchanged. BUG-1383.

Co-Authored-By: Grok (agent loop)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-18 16:20:35 +08:00

43 lines
1.7 KiB
Python

"""Synthetic angular fixtures; no birth records or predictive assertions."""
from fractions import Fraction
import math
import pytest
from scripts.kp_system import get_kp_lords
ORDER='Ketu Venus Sun Moon Mars Rahu Jupiter Saturn Mercury'.split()
YEARS=(7,20,6,10,7,18,16,19,17)
def test_every_subsub_boundary_is_left_closed_right_open():
starts=[]
for star in range(27):
start=Fraction(star*40,3)
for offset in range(9):
sub=(star+offset)%9;span=Fraction(40*YEARS[sub],360)
for child_offset in range(9):
child=(sub+child_offset)%9
starts.append((float(start),ORDER[sub],ORDER[child]))
start+=span*YEARS[child]/120
for i,(angle,sub,child) in enumerate(starts):
for probe in (angle,math.nextafter(angle,math.inf)):
actual=get_kp_lords(probe)
assert (actual['sub_lord'],actual['sub_sub_lord'])==(sub,child)
if i:
before=get_kp_lords(math.nextafter(angle,-math.inf))
assert (before['sub_lord'],before['sub_sub_lord'])==starts[i-1][1:]
def test_quarter_boundaries_and_wrap():
for i in range(108):
degree=float(Fraction(10*i,3))
assert get_kp_lords(degree)['pada']==i%4+1
if i:assert get_kp_lords(math.nextafter(degree,-math.inf))['pada']==(i-1)%4+1
assert get_kp_lords(70)['pada']==2
assert get_kp_lords(360)==get_kp_lords(0)
assert get_kp_lords(-1)==get_kp_lords(359)
@pytest.mark.parametrize('invalid',[True,None,'70',float('nan'),float('inf'),float('-inf')])
def test_nonfinite_or_nonnumeric_longitude_rejected(invalid):
with pytest.raises(ValueError):get_kp_lords(invalid)