-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patheven_int.py
More file actions
51 lines (34 loc) · 854 Bytes
/
even_int.py
File metadata and controls
51 lines (34 loc) · 854 Bytes
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
#!/usr/bin/env python
"""
Using new to create an even integer
rounds the input to the nearest even integer.
will even convert a string to an int...
"""
##subclassing an int
class EvenInt(int):
"""
An integer that is always even
"""
pass
## And some tests -- try with py.test or nosetests...
def test_subclass():
assert issubclass(EvenInt, int)
def test_instance():
i = EvenInt(3)
assert isinstance(i, int)
def test_even():
assert EvenInt(4) == 4
def test_odd1():
assert EvenInt(3) == 4
def test_odd2():
assert EvenInt(2.99) == 2
def test_negative():
assert EvenInt(-2) == -2
def test_negative_odd():
assert EvenInt(-1) == -2
def test_negative_odd2():
assert EvenInt(-1.1) == -2
def test_string_odd():
assert EvenInt("3") == 4
def test_string_even():
assert EvenInt("12") == 12