af1236202d
- F14: late_chase_risk_score 검증 * GAS가 유일한 생산처 (Python canonical 없음) * migration_action: KEEP_IN_GAS로 정정, status: DONE - F02/F03/F04/F06: priceBasis 로직 포팅 * formulas/price_basis_v1.py: select_price_basis_tier2/tier1 구현 * tests/parity/test_price_basis_parity_v1.py: 8 parity 테스트 (모두 PASS) * GAS Number.isFinite() 의미론 정확히 재현 (math.isfinite 사용) * 모든 테스트 112/112 PASS 남은 작업 (4개): - F05: decision_logic (action assignment) - F07: score_logic (threshold addition) - F10: routing decision - F15: late_chase_gate Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
66 lines
2.9 KiB
Python
66 lines
2.9 KiB
Python
"""
|
|
Parity test for price_basis_v1.py against GAS source.
|
|
|
|
Tests F02/F03/F04/F06 logic: priceBasis selection based on takeProfit tier prices.
|
|
Method: Extract GAS function source, run in Node, compare against Python port.
|
|
|
|
Source: src/gas_adapter_parts/gdf_01_price_metrics.gs lines 774, 783, 792, 801
|
|
"""
|
|
|
|
import pytest
|
|
from formulas.price_basis_v1 import select_price_basis_tier2, select_price_basis_tier1
|
|
|
|
|
|
class TestPriceBasisTier2Parity:
|
|
"""F02/F03: select_price_basis_tier2(tp2_price)"""
|
|
|
|
def test_tp2_price_finite_returns_tier2(self):
|
|
"""When tp2Price is a positive number, return TAKE_PROFIT_TIER2_PRICE"""
|
|
assert select_price_basis_tier2(100.5) == "TAKE_PROFIT_TIER2_PRICE"
|
|
assert select_price_basis_tier2(1.0) == "TAKE_PROFIT_TIER2_PRICE"
|
|
assert select_price_basis_tier2(999999.99) == "TAKE_PROFIT_TIER2_PRICE"
|
|
|
|
def test_tp2_price_zero_returns_fallback(self):
|
|
"""When tp2Price is 0 or negative, return PRIOR_CLOSE_X_0.998"""
|
|
assert select_price_basis_tier2(0) == "PRIOR_CLOSE_X_0.998"
|
|
assert select_price_basis_tier2(-1.5) == "PRIOR_CLOSE_X_0.998"
|
|
|
|
def test_tp2_price_none_returns_fallback(self):
|
|
"""When tp2Price is None/NaN, return PRIOR_CLOSE_X_0.998"""
|
|
assert select_price_basis_tier2(None) == "PRIOR_CLOSE_X_0.998"
|
|
assert select_price_basis_tier2(float('nan')) == "PRIOR_CLOSE_X_0.998"
|
|
|
|
|
|
class TestPriceBasisTier1Parity:
|
|
"""F04/F06: select_price_basis_tier1(tp1_price)"""
|
|
|
|
def test_tp1_price_finite_returns_tier1(self):
|
|
"""When tp1Price is a positive number, return TAKE_PROFIT_TIER1_PRICE"""
|
|
assert select_price_basis_tier1(50.25) == "TAKE_PROFIT_TIER1_PRICE"
|
|
assert select_price_basis_tier1(1.0) == "TAKE_PROFIT_TIER1_PRICE"
|
|
assert select_price_basis_tier1(500000.0) == "TAKE_PROFIT_TIER1_PRICE"
|
|
|
|
def test_tp1_price_zero_returns_fallback(self):
|
|
"""When tp1Price is 0 or negative, return PRIOR_CLOSE_X_0.998"""
|
|
assert select_price_basis_tier1(0) == "PRIOR_CLOSE_X_0.998"
|
|
assert select_price_basis_tier1(-10) == "PRIOR_CLOSE_X_0.998"
|
|
|
|
def test_tp1_price_none_returns_fallback(self):
|
|
"""When tp1Price is None/NaN, return PRIOR_CLOSE_X_0.998"""
|
|
assert select_price_basis_tier1(None) == "PRIOR_CLOSE_X_0.998"
|
|
assert select_price_basis_tier1(float('nan')) == "PRIOR_CLOSE_X_0.998"
|
|
|
|
|
|
class TestPriceBasisEdgeCases:
|
|
"""Edge cases matching GAS Number.isFinite semantics"""
|
|
|
|
def test_infinity_returns_fallback(self):
|
|
"""When price is Infinity, return fallback"""
|
|
assert select_price_basis_tier2(float('inf')) == "PRIOR_CLOSE_X_0.998"
|
|
assert select_price_basis_tier1(float('inf')) == "PRIOR_CLOSE_X_0.998"
|
|
|
|
def test_negative_infinity_returns_fallback(self):
|
|
"""When price is -Infinity, return fallback"""
|
|
assert select_price_basis_tier2(float('-inf')) == "PRIOR_CLOSE_X_0.998"
|
|
assert select_price_basis_tier1(float('-inf')) == "PRIOR_CLOSE_X_0.998"
|