-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
56 lines (42 loc) · 1.29 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
import math
from fraction_definition import Fraction
if __name__ == '__main__':
assert str(Fraction(3, 4)) == '3/4'
assert Fraction(3/4) == Fraction('0.75') == Fraction(0.75) == Fraction('3/4')
zero = Fraction(0)
quarter = Fraction(0.25)
half = Fraction(0.5)
three_quarters = Fraction(0.75)
one = Fraction(1)
one_and_half = Fraction(1.5)
two = Fraction(2)
minus_half = Fraction(-0.5)
minus_one = Fraction(-1)
minus_two = Fraction(-2)
assert Fraction() == zero
# Equality
assert half != one
assert Fraction(50, 100) == half
assert Fraction(200, 6) == Fraction(100, 3)
assert Fraction(0.333) != Fraction(1, 3)
# Arithmetic Operations
assert three_quarters + half == one + quarter == Fraction(1.25)
assert half - one == minus_half
assert half * half == quarter
assert half / half == one
# String representation
assert str(Fraction(3.13)) == '313/100'
assert str(Fraction(50, 100)) == '1/2'
# Assignment - by value
f1 = half
f1 /= half
assert f1 == one
assert half != one
# Comparison Operators
assert one < two
assert two <= two
assert one >= one
# Math Operators
assert abs(minus_one) == one
assert math.ceil(half) == one
assert math.floor(half) == zero