File size: 1,255 Bytes
16038fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import annotations

from fsds_cleaning_env.reward import (
    FinalRewardInput,
    StepRewardInput,
    TOOL_ERROR_REWARD,
    compute_final_reward,
    compute_quality_gate_bonus,
    compute_step_reward,
)


def test_step_reward_positive_improvement() -> None:
    inp = StepRewardInput(quality_before=0.5, quality_after=0.7)
    reward = compute_step_reward(inp)
    # Delta = 0.2, minus margin 0.02 => 0.18
    assert abs(reward - 0.18) < 1e-6


def test_step_reward_negative_clipped() -> None:
    inp = StepRewardInput(quality_before=0.5, quality_after=0.2)
    reward = compute_step_reward(inp)
    # Delta = -0.3, minus margin 0.02 => -0.32, clipped to -0.15
    assert abs(reward - (-0.15)) < 1e-6


def test_quality_gate_bonus() -> None:
    assert compute_quality_gate_bonus(True) == 0.15
    assert compute_quality_gate_bonus(False) == -0.1


def test_final_reward_combination() -> None:
    inp = FinalRewardInput(
        quality_score=1.0,
        gate_passed=True,
        required_operation_coverage=1.0,
    )
    reward = compute_final_reward(inp)
    # 0.45 * 1.0 + 0.30 * 1.0 + 0.25 * 1.0 = 1.0
    assert abs(reward - 1.0) < 1e-6


def test_tool_error_reward_constant() -> None:
    assert TOOL_ERROR_REWARD < 0.0