"""CPU source-derived rotation oracle; no CUDA or CFD initialization."""
from pathlib import Path
import numpy as np
import pytest

ROOT=Path(__file__).resolve().parents[3]

def test_nominal_rotation_conversion_and_discrete_geometry_factor():
    R, u_s = 5.0, 0.7
    omega = u_s / R
    assert omega > 0  # positive legacy tangential speed maps to positive modern omega
    legacy_center_vector = np.array([2.0, -3.0])
    modern_hit_vector = np.array([2.25, -3.25])
    legacy = u_s * np.array([-legacy_center_vector[1], legacy_center_vector[0]]) / R
    modern = omega * np.array([-modern_hit_vector[1], modern_hit_vector[0]])
    assert np.allclose(legacy, omega * np.array([-legacy_center_vector[1], legacy_center_vector[0]]))
    assert not np.allclose(legacy, modern)  # distinct discrete lever arms need not have norm R
    assert np.linalg.norm(modern) / np.linalg.norm(legacy) == pytest.approx(
        np.linalg.norm(modern_hit_vector) / np.linalg.norm(legacy_center_vector)
    )
    a=np.array([0.0,-1.0,1.0]); scale=8.0; bias=np.array([0.0,-4.0,4.0]); U0=0.01
    assert np.allclose(-(a*scale+bias)*U0/R, np.array([0.0,12.0,-12.0])*U0/R)

def test_oracle_is_bound_to_maintained_sources():
    modern=(ROOT/'CelerisLab/src/CelerisLab/lbm/kernels/step/aux_kernels.cu').read_text()
    legacy=(ROOT/'LegacyCelerisLab/driver.py').read_text()
    policy=(ROOT/'src/drl_pinball/train/env_karman.py').read_text()
    geometry=(ROOT/'CelerisLab/src/CelerisLab/body/geometry/circle.py').read_text()
    render=(ROOT/'CelerisLab/src/CelerisLab/common/render.py').read_text()
    assert 'Uw = -omega * ry' in modern and 'Vw =  omega * rx' in modern
    assert '(y_c - y) / radius' in legacy and '(x - x_c) / radius' in legacy
    assert 'return -sv / RADIUS' in policy
    assert 'fluid_idx=x + y * nx' in geometry and 'origin="lower"' in render
