-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
168 lines (128 loc) · 7.78 KB
/
tests.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import kappa
import kappa_simple
import lins_concordance
class BaseTest(unittest.TestCase):
def must_contain(self, text, token):
self.assertTrue(token in text)
class KappaTests(BaseTest):
def test_eval_01(self):
# --npp 1.0 --npa 1.0 --nap 2.0 --naa 2.0 --kappatest 0.5
output = kappa.calculate_kappa(1.0, 1.0, 2.0, 2.0, 0.5)
self.must_contain(output, 'present | 1 | 1')
self.must_contain(output, 'absent | 2 | 2')
self.must_contain(output, '= 0.3849')
self.must_contain(output, 'kappa= 0.5] = 0.9030')
def test_eval_02(self):
# --npp 100.0 --npa 100.0 --nap 1.0 --naa 1.0 --kappatest 0.5
output = kappa.calculate_kappa(100.0, 100.0, 1.0, 1.0, 0.5)
self.must_contain(output, 'present | 100 | 100')
self.must_contain(output, 'absent | 1 | 1')
self.must_contain(output, '= 0.0139')
self.must_contain(output, 'kappa= 0.5] > 0.9999')
def test_eval_03(self):
# --npp 100.0 --npa 100.0 --nap 1.0 --naa 1.0 --kappatest 0
output = kappa.calculate_kappa(100.0, 100.0, 1.0, 1.0, 0)
self.must_contain(output, 'present | 100 | 100')
self.must_contain(output, 'absent | 1 | 1')
self.must_contain(output, '= 0.0139')
self.must_contain(output, 'kappa=0] = 0.5000')
self.must_contain(output, 'kappa= 0.0] > 0.9999')
def test_kappa_less_than_zero(self):
output = kappa.calculate_kappa(1.0, 1.0, 2.0, 2.0, -1)
self.must_contain(output, 'Kappatest must be greater than or equal to zero and less than 1')
def test_kappa_validate_input_01(self):
output = kappa.calculate_kappa(1.0, 0.0, 0.0, 0.0, 0.5)
self.must_contain(output, 'Perfect agreement (all rating pairs are "present")')
def test_kappa_validate_input_02(self):
output = kappa.calculate_kappa(0.0, 1.0, 0.0, 0.0, 0.5)
self.must_contain(output, 'Perfect disagreement (all rating pairs are "present"/"absent")')
def test_kappa_validate_input_03(self):
output = kappa.calculate_kappa(0.0, 0.0, 1.0, 0.0, 0.5)
self.must_contain(output, 'Perfect disagreement (all rating pairs are "present"/"absent")')
def test_kappa_validate_input_04(self):
output = kappa.calculate_kappa(0.0, 0.0, 0.0, 1.0, 0.5)
self.must_contain(output, 'Perfect agreement (all rating pairs are "absent")')
def test_kappa_validate_input_05(self):
output = kappa.calculate_kappa(0.0, 1.0, 1.0, 0.0, 0.5)
self.must_contain(output, 'Perfect disagreement (some rating pairs are "present/absent", all others are "absent/present")')
def test_kappa_validate_input_06(self):
output = kappa.calculate_kappa(1.0, 0.0, 1.0, 0.0, 0.5)
self.must_contain(output, 'Rater B has marked all tests as "present"; rater A has "present" and "absent"')
def test_kappa_validate_input_07(self):
output = kappa.calculate_kappa(0.0, 1.0, 0.0, 1.0, 0.5)
self.must_contain(output, 'Rater B has marked all tests as "absent"; rater A has "present" and "absent"')
def test_kappa_validate_input_08(self):
output = kappa.calculate_kappa(1.0, 1.0, 0.0, 0.0, 0.5)
self.must_contain(output, 'Rater A has marked all tests as "present"; rater B has "present" and "absent"')
def test_kappa_validate_input_09(self):
output = kappa.calculate_kappa(0.0, 0.0, 1.0, 1.0, 0.5)
self.must_contain(output, 'Rater A has marked all tests as "absent"; rater B has "present" and "absent"')
def test_kappa_validate_input_10(self):
output = kappa.calculate_kappa(1.0, 0.0, 0.0, 1.0, 0.5)
self.must_contain(output, 'Perfect agreement (some rating pairs are "present", all others are "absent")')
class KappaSimpleTests(BaseTest):
def test_eval_01(self):
# --npp 1.0 --npa 1.0 --nap 2.0 --naa 2.0 --kappa_simpletest 0.5
output = kappa_simple.calculate_kappa(1.0, 1.0, 2.0, 2.0, 0.5)
self.must_contain(output, 'present | 1 | 1')
self.must_contain(output, 'absent | 2 | 2')
self.must_contain(output, '= 0.3849')
self.must_contain(output, 'kappa= 0.5] = 0.9030')
def test_eval_02(self):
# --npp 0.0 --npa 0.1 --nap 1.0 --naa 0.0 --kappa_simpletest 0.5
output = kappa_simple.calculate_kappa(0.0, 0.1, 1.0, 0.0, 0.5)
self.must_contain(output, 'present | 0 | 0')
self.must_contain(output, 'absent | 1 | 0')
self.must_contain(output, 'estimated kappa = -0.198')
self.must_contain(output, '= 0.6437')
self.must_contain(output, 'kappa= 0.5] = 0.8608')
def test_eval_03(self):
# --npp 0.0 --npa 1.0 --nap 1.0 --naa 0.0 --kappa_simpletest 0.5
with self.assertRaises(ZeroDivisionError):
kappa_simple.calculate_kappa(0.0, 1.0, 1.0, 0.0, 0.5)
def test_kappa_less_than_zero(self):
output = kappa_simple.calculate_kappa(1.0, 1.0, 2.0, 2.0, -1)
self.must_contain(output, 'Kappatest must be greater than or equal to zero and less than 1')
def test_kappa_validate_input_01(self):
output = kappa_simple.calculate_kappa(1.0, 0.0, 0.0, 0.0, 0.5)
self.must_contain(output, 'Perfect agreement (all rating pairs are "present")')
def test_kappa_validate_input_02(self):
output = kappa_simple.calculate_kappa(0.0, 1.0, 0.0, 0.0, 0.5)
self.must_contain(output, 'Perfect disagreement (all rating pairs are "present"/"absent")')
def test_kappa_validate_input_03(self):
output = kappa_simple.calculate_kappa(0.0, 0.0, 1.0, 0.0, 0.5)
self.must_contain(output, 'Perfect disagreement (all rating pairs are "present"/"absent")')
def test_kappa_validate_input_04(self):
output = kappa_simple.calculate_kappa(0.0, 0.0, 0.0, 1.0, 0.5)
self.must_contain(output, 'Perfect agreement (all rating pairs are "absent")')
def test_kappa_validate_input_05(self):
output = kappa_simple.calculate_kappa(1.0, 0.0, 1.0, 0.0, 0.5)
self.must_contain(output, 'Rater B has marked all tests as "present"; rater A has "present" and "absent"')
def test_kappa_validate_input_06(self):
output = kappa_simple.calculate_kappa(0.0, 1.0, 0.0, 1.0, 0.5)
self.must_contain(output, 'Rater B has marked all tests as "absent"; rater A has "present" and "absent"')
def test_kappa_validate_input_07(self):
output = kappa_simple.calculate_kappa(1.0, 1.0, 0.0, 0.0, 0.5)
self.must_contain(output, 'Rater A has marked all tests as "present"; rater B has "present" and "absent"')
def test_kappa_validate_input_08(self):
output = kappa_simple.calculate_kappa(0.0, 0.0, 1.0, 1.0, 0.5)
self.must_contain(output, 'Rater A has marked all tests as "absent"; rater B has "present" and "absent"')
def test_kappa_validate_input_09(self):
output = kappa_simple.calculate_kappa(1.0, 0.0, 0.0, 1.0, 0.5)
self.must_contain(output, 'Perfect agreement (some rating pairs are "present", all others are "absent")')
class LinsConcordanceTests(BaseTest):
def test_lins_concordance_eval_01(self):
output = lins_concordance.calculate_concordance('1~2~2~3~3~4')
self.must_contain(output, 'Sample concordance correlation coefficient (pc) = 0.5714')
self.must_contain(output, 'Lower one-sided 95% CL for pc = -0.193')
self.must_contain(output, 'Lower two-sided 95% CL for pc = -0.343')
self.must_contain(output, 'Upper one-sided 95% CL for pc = 0.9043')
self.must_contain(output, 'Upper two-sided 95% CL for pc = 0.9298')
def test_lins_concordance_input_01(self):
with self.assertRaises(IndexError):
lins_concordance.calculate_concordance('1~2~2~3~3')
if __name__ == '__main__':
unittest.main()