File size: 1,136 Bytes
1e3b07a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
"""Tests for Code Debugging Challenge environment."""

import pytest
from server.debug_environment import DebugEnvironment
from models import DebugAction


def test_environment_reset():
    """Test environment reset."""
    env = DebugEnvironment()
    obs = env.reset()
    
    assert obs.buggy_code is not None
    assert obs.expected_output is not None
    assert obs.attempts_remaining == 5
    assert not obs.success


def test_analyze_action():
    """Test analyze action."""
    env = DebugEnvironment()
    env.reset()
    
    action = DebugAction(action_type="analyze")
    obs = env.step(action)
    reward = env.reward(obs)
    
    assert reward == 0.1
    assert not env.terminated(obs)


def test_successful_fix():
    """Test successful bug fix."""
    env = DebugEnvironment()
    env.reset()
    
    correct_fix = env.current_problem["fixed_code"]
    action = DebugAction(action_type="fix", content=correct_fix)
    obs = env.step(action)
    reward = env.reward(obs)
    
    assert obs.success
    assert reward == 1.0
    assert env.terminated(obs)


if __name__ == "__main__":
    pytest.main([__file__, "-v"])