-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·79 lines (49 loc) · 1.94 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
#!/usr/bin/env python
import itertools
import unittest
import continued
class HelperTest(unittest.TestCase):
def test_gcd_examples(self):
self.assertEqual(continued.gcd(3, 6), 3)
self.assertEqual(continued.gcd(19872, 526293), 9)
class ContinuedBugfixTest(unittest.TestCase):
def test_one(self):
one = continued.Rational(1, 1)
class ContinuedFunctionalityTest(unittest.TestCase):
def test_arithmetic(self):
first = continued.Rational(3, 5)
second = continued.Rational(7, 11)
third = continued.Rational(68, 55)
self.assertTrue(first + second == third)
fourth = continued.Rational(21, 55)
self.assertTrue(first * second == fourth)
def test_comparisons(self):
smaller = continued.Rational(100, 89)
larger = continued.Rational(244, 217)
self.assertTrue(smaller < larger)
threeonefive = continued.Continued.from_float(3.15)
pi = continued.Pi()
self.assertTrue(threeonefive > pi)
one = continued.Rational(1, 1)
self.assertTrue(one == one)
def test_e(self):
e = continued.E()
digits = list(itertools.islice(e.digits(), 5))
self.assertEqual(digits, [2, 1, 2, 1, 1])
def test_phi(self):
phi = continued.Phi()
digits = list(itertools.islice(phi.digits(), 5))
self.assertEqual(digits, [1, 1, 1, 1, 1])
def test_pi(self):
pi = continued.Pi()
digits = list(itertools.islice(pi.digits(), 5))
self.assertEqual(digits, [3, 7, 15, 1, 292])
def test_rational(self):
eighth = continued.Rational(1, 8)
self.assertEqual(list(eighth.digits()), [0, 8])
fortytwo = continued.Rational(42, 10)
self.assertEqual(list(fortytwo.digits()), [4, 5])
fiveeighths = continued.Rational(5, 8)
self.assertEqual(list(fiveeighths.digits()), [0, 1, 1, 1, 2])
if __name__ == "__main__":
unittest.main()