-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
135 lines (113 loc) · 3.84 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import unittest
class Test_Assignment_01(unittest.TestCase):
"""
Below are a series of tests, some of which will fail.
Automated testing will be performed when you submit a
Pull Request and any time that you make any future
modification to the file.
If you get stuck, launch a Python interpreter (Python,
iPython, or Jupyter Notebook) and copy a small block of
code.
For example, if the test reads:
x = 'abcde'
self.assertEqual(4, len(x))
and you are unsure what len(x) might return, you can
execute:
>>> x = 'abcde'
>>> len(x)
5
in any of the above interpreters.
"""
def setUp(self):
"""
Code called before every other test is run.
"""
pass
def test_assert_truth(self):
"""
A test that will pass.
"""
self.assertTrue(True)
def test_assert_truth_with_a_message(self):
"""
A test that will "no longer" fail. The only way this will not
fail is by changing the word in the brackets to False. We
are adding what will fail.
"""
self.assertFalse(False, 'This should fail, please fix it.')
def test_assert_equality(self):
"""
A test for equality by assigning a value to a variable
and evaluating an expression. An Expected value has been added.
"""
expected_value = 2
truth_value = 1 + 1
self.assertEqual(expected_value, truth_value)
def test_what_are_these_types(self):
"""
A test to know what the types of the previous fixes were
True switched to false
"""
self.assertFalse(False, bool)
def test_assert_string(self):
"""
A test for evaluating an expression
"""
my_string = 'Hello World'
my_string_length = len(my_string) # The expression
self.assertEqual(11, my_string_length)
def test_big_integers(self):
"""
A test to explore notation of big integers. I removed the
comma. I was going to add a line that removed the comma but
realized it was just easier to remove the comma. x.replace(',','')
commas are generally used to deliniate
"""
x = 42000
self.assertTrue(isinstance(x, int))
def test_bigger_integers(self):
"""
A test for bigger, or smaller integers
I changed the assert to GreaterEqual and LessEqual to use better verification
"""
big = 1e6
self.assertGreaterEqual(big, 100)
self.assertTrue(type(big), int)
small = 1e-5
self.assertLessEqual(small, 0.0001)
self.assertTrue(type(small), int)
def test_type_conversion(self):
"""
A series of tests to validate type conversion operations
changed last line to not equals for false str
"""
i = 1
self.assertTrue(type(i) == int)
self.assertTrue(isinstance(i, int)) # These lines do the same type checking
i = float(i)
self.assertTrue(isinstance(i, float))
i = str(i)
self.assertFalse(type(i) != str)
def test_type_conversion2(self):
"""
A poorly named function to test converting strings to numeric types
"""
k = "123"
self.assertIsInstance(k, str) # New assertion type that shortens previous calls
k = float(k)
self.assertEqual(123, k) # Hmmm, note how this equality works across types
def test_type_conversion_gotcha(self):
"""
A test to show how rounding can get you
it rounds down
"""
j = 3.9999
self.assertTrue(int(j), float)
self.assertEqual(int(j), 3)
def tearDown(self):
"""
Code called after ever other test is run.
"""
pass
if __name__ == '__main__':
unittest.main()