-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pair.py
56 lines (42 loc) · 1.5 KB
/
test_pair.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
from __future__ import division
import unittest
from jaccard import j
class TestJ(unittest.TestCase):
def test_fails_on_no_args(self):
with self.assertRaises(TypeError):
j()
def test_fails_on_one_arg(self):
with self.assertRaises(TypeError):
j(1)
def test_fails_on_three_args(self):
with self.assertRaises(TypeError):
j(1, 2, 3)
def test_one_for_same(self):
result = j([1, 2, 3], [1, 2, 3])
self.assertEqual(result, 1)
def test_result_is_float(self):
result = j([1, 2, 3], [1, 2, 3])
self.assertIs(type(result), type(1.0))
def test_order_not_important(self):
result = j([3, 2, 1], [1, 3, 2])
self.assertEqual(result, 1)
def test_zero_for_different(self):
result = j([1, 2, 3], [4, 5, 6])
self.assertEqual(result, 0)
def test_half_for_double(self):
result = j(['cow'], ['dog', 'cow'])
self.assertEqual(result, 0.5)
def test_third_for_half_same(self):
result = j([1, 2], [2, 3])
self.assertEqual(result, 1/3)
def test_half_for_two_thirds_same(self):
result = j([1, 2, 3], [2, 3, 4])
self.assertEqual(result, 0.5)
def test_immune_to_duplicates(self):
result = j([1, 1, 2], [3, 3, 3, 2, 2])
self.assertEqual(result, 1/3)
def test_larger_lists(self):
result = j(range(1, 10), [10, 9, 8, 7, 6])
self.assertEqual(result, 2/5)
if __name__ == '__main__':
unittest.main()