# tests/test_reward_functions.py
import pytest
from reward_fn.compute_reward import numbers_match_reward
def test_exact_match():
"""Test exact numerical match"""
score = numbers_match_reward("#### 42", "42")
assert score == 1.0
def test_close_match():
"""Test near-match within epsilon"""
score = numbers_match_reward("#### 42.0000001", "42")
assert score == 1.0
def test_mismatch():
"""Test completely different values"""
score = numbers_match_reward("#### 100", "42")
assert score == 0.0
def test_invalid_format():
"""Test handling of invalid input format"""
score = numbers_match_reward("no number here", "42")
assert score == 0.0
def test_missing_solution():
"""Test handling of empty solution"""
score = numbers_match_reward("", "42")
assert score == 0.0
@pytest.mark.parametrize("solution,ground_truth,expected", [
("#### 1", "1", 1.0),
("#### 0", "0", 1.0),
("#### -5", "-5", 1.0),
("#### 3.14159", "3.14159", 1.0),
])
def test_various_numbers(solution, ground_truth, expected):
"""Test various number formats"""
score = numbers_match_reward(solution, ground_truth)
assert score == expected