-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cases.py
83 lines (59 loc) · 2.28 KB
/
test_cases.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import math
test_cases_p_word_given_class = {'opinions': 0.0018821,
'yet': 0.003764,
'away': 0.0018821,
'interested': 0.0025094,
'extended': 0.0018821,
'married': 0.0018821,
'received': 0.0018821,
'adapted': 0.0018821,
'remainder': 0.0018821,
'behind': 0.0018821,
'pain': 0.0025094,
'old': 0.0025094,
'private': 0.0018821,
'solicitude': 0.0031368,
'examine': 0.0012547,
'removal': 0.0025094,
'unaffected': 0.0012547,
'late': 0.0018821,
'sold': 0.003764,
'UNKNOWN_WORD': 0.0006274}
def test_compute_p_word_given_class():
from probabilities import compute_p_word_given_class
train_paths = ['data/test_text/test_text_' + str(i) + '.txt' for i in range(1,6)]
student_solution = compute_p_word_given_class(train_paths, 100)
test_cases = test_cases_p_word_given_class
count_correct = 0
for word in test_cases:
if math.isclose(student_solution[word], test_cases[word], abs_tol = 1e-6):
count_correct+=1
result = str(count_correct) + ' out of ' + str(len(test_cases)) + ' correct'
print(result)
def test_compute_p_class():
from probabilities import compute_p_class
test_cases = {(1,1): 0.5, (1,2): 0.4, (2,1): 0.6, (2,2): 0.5, (3,3): 0.5, (4,2): 0.625, (4,4): 0.5}
count_correct = 0
for i,j in test_cases:
if compute_p_class(i, j) == test_cases[(i,j)]: count_correct += 1
result = str(count_correct) + ' out of ' + str(len(test_cases)) + ' correct'
print(result)
def test_compute_p_class_given_input():
from probabilities import compute_p_class_given_input
test_paths = ['data/test_text/test_text_' + str(i) + '.txt' for i in range(1,6)]
test_cases = [-2012.09438, -2216.4758, -2088.3987, -2266.9948, -2360.9622]
p_wc = test_cases_p_word_given_class
p_c = 1
count_correct = 0
for i, test_path in enumerate(test_paths):
if math.isclose(compute_p_class_given_input(test_path, p_wc, p_c), test_cases[i], abs_tol = 1e-3):
count_correct += 1
result = str(count_correct) + ' out of ' + str(len(test_cases)) + ' correct'
print(result)
if __name__ == '__main__':
print('compute_p_word_given_class')
test_compute_p_word_given_class()
print('\ncompute_p_class')
test_compute_p_class()
print('\ncompute_p_class_given_input')
test_compute_p_class_given_input()