File size: 1,020 Bytes
6e7ce30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import os
# Add parent directory to path to import environment
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from environment.graders import grade_easy, grade_medium, grade_hard
from environment.models import Issue

def test_grader_variance():
    # Perfect score
    perfect = [
        Issue(line=8, category="bug", description=""),
        Issue(line=2, category="documentation", description="")
    ]
    assert grade_easy(perfect) == 1.0
    
    # Empty
    assert grade_easy([]) == 0.0
    
    # Partial
    partial = [Issue(line=8, category="bug", description="")]
    # F1 score for partial match should be between 0 and 1
    # TP=1, FP=0, FN=1 -> P=1, R=0.5 -> F1 = 2*(1*0.5)/(1+0.5) = 2/3 = 0.667
    assert grade_easy(partial) == 0.667
    
    # False positive
    fp = [Issue(line=99, category="bug", description="")]
    assert grade_easy(fp) == 0.0
    
    print("All grader variance tests passed.")

if __name__ == "__main__":
    test_grader_variance()