-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_is_even.py
61 lines (47 loc) · 1.46 KB
/
test_is_even.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
import unittest
from sys import version_info
from is_even import is_even
class TestIsEven(unittest.TestCase):
def test_even(self):
even = is_even.is_even(2)
self.assertTrue(even)
def test_odd(self):
odd = is_even.is_odd(3)
self.assertTrue(odd)
def test_not_even(self):
even = is_even.is_even(3)
self.assertFalse(even)
def test_not_odd(self):
even = is_even.is_odd(2)
self.assertFalse(even)
def test_cache(self):
self.assertTrue(is_even.is_even(2))
self.assertFalse(is_even.is_even(3))
def test_negative(self):
with self.assertRaises(Exception):
is_even.is_even(-10)
def test_failback_even(self):
v = 2
if version_info >= (3, 0):
even = list(is_even._is_even(v))[-1]
else:
even = is_even._is_even(v)
self.assertTrue(even)
def test_failback_odd(self):
v = 3
if version_info >= (3, 0):
odd = list(is_even._is_even(v))[-1]
else:
odd = is_even._is_even(v)
self.assertFalse(odd)
def test_ad(self):
if version_info >= (3, 0):
v = is_even.is_even(0)
self.assertTrue(isinstance(v.ad, str))
def test_ad_cached(self):
v = is_even.is_even(0)
y = is_even.is_even(0)
if version_info >= (3, 0):
self.assertEqual(v.ad, y.ad)
if __name__ == "__main__":
unittest.main()