-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2-matrix_divided.txt
More file actions
201 lines (153 loc) · 6.29 KB
/
2-matrix_divided.txt
File metadata and controls
201 lines (153 loc) · 6.29 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# 2-matrix_divided.txt
# Run: python3 -m doctest -v ./tests/2-matrix_divided.txt
Importing function from the module:
>>> matrix_divided = __import__('2-matrix_divided').matrix_divided
Dividing a matrix by 3:
>>> matrix_divided([[1, 2, 3], [4, 5, 6]], 3)
[[0.33, 0.67, 1.0], [1.33, 1.67, 2.0]]
Dividing a matrix by 0:
>>> matrix_divided([[1, 2, 3], [4, 5, 6]], 0)
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
Dividing a matrix by a float number:
>>> matrix_divided([[10, 20, 30], [1.33, 3.74, 6.89], [-8, -9.71, 0]], 5.3)
[[1.89, 3.77, 5.66], [0.25, 0.71, 1.3], [-1.51, -1.83, 0.0]]
Passing an empty matrix:
>>> matrix_divided([], 10)
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Passing a tuple as an argument:
>>> matrix_divided((3, 6, 9), 3)
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Dividing a matrix which its rows don't have the same size:
>>> matrix_divided([[22, 34], [2.78, 7.1, -10, 2], [-8]], 3)
Traceback (most recent call last):
...
TypeError: Each row of the matrix must have the same size
Dividing a matrix which its rows don't have the same size 2:
>>> matrix_divided([[2, 4], [6.8], [10, 12]], 12)
Traceback (most recent call last):
...
TypeError: Each row of the matrix must have the same size
Dividing a matrix which its elements aren't integer/float numbers:
>>> matrix_divided([["Hello", "World"], ["Hello", "Holberton"]], 10)
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Dividing a matrix which its elements aren't integer/float numbers 2:
>>> matrix_divided([["1"], ["2", "3"], ["5", "6", "7"]], 10)
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Dividing a matrix which some of its elements aren't integer/float numbers:
>>> matrix_divided([[2.7, 4], ['6', 8.4], [10.1, '12'], [5.3, '10.2', 15.8]], 5)
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Passing a matrix which one of its elements is an empty list:
>>> matrix_divided([[2.1, 5.8], [], [10, -3]], 8)
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Passing a matrix which one of its elements is a tuple:
>>> matrix_divided([[1, -1], (2, -2), [3, -3]], 1)
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Passing div as a list
>>> matrix_divided([[5.7, 8.1], [7.7, 4.9]], [2])
Traceback (most recent call last):
...
TypeError: div must be a number
Passing div as a string
>>> matrix_divided([[10, 50], [30, 20]], "10")
Traceback (most recent call last):
...
TypeError: div must be a number
Dividing a matrix which has positive and negative integer/float numbers
>>> matrix_divided([[-1, 3.1, 0], [78, -103.7, 54]], 9.2)
[[-0.11, 0.34, 0.0], [8.48, -11.27, 5.87]]
Test empty matrix:
>>> print(matrix_divided(None, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
>>> matrix = []
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
>>> matrix = [[], [], []]
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Test different sized lists in matrix:
>>> matrix = [[1, 2, 3], [4]]
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: Each row of the matrix must have the same size
>>> matrix = [[1, 2, 3], [4, 5, 6], [7]]
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: Each row of the matrix must have the same size
Test matrix with other data types:
>>> matrix = [["hey"], ["you"]]
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
>>> matrix = [[1, 2, 3], {"key" : 4}]
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
>>> matrix = [[1, 2], 3, {4, 5}]
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
>>> matrix = {1, 2, 3, 4}
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
>>> matrix = ([1, 2], [3, 4])
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
>>> matrix = [[1, 2], [3, (4, 5)]]
>>> print(matrix_divided(matrix, 2))
Traceback (most recent call last):
...
TypeError: matrix must be a matrix (list of lists) of integers/floats
Test extra args:
>>> matrix = [[1, 2, 3], [4, 5, 6.7]]
>>> print(matrix_divided(matrix, 2, 100))
Traceback (most recent call last):
...
TypeError: matrix_divided() takes 2 positional arguments but 3 were given
Test too few args
>>> matrix = [[1, 2], [3, 4]]
>>> print(matrix_divided(matrix))
Traceback (most recent call last):
...
TypeError: matrix_divided() missing 1 required positional argument: 'div'
Test div as 0 or non-int or non-float:
>>> matrix = [[1, 2], [3, 4]]
>>> print(matrix_divided(matrix, 0))
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
>>> matrix = [[1, 2], [3, 4]]
>>> print(matrix_divided(matrix, "2"))
Traceback (most recent call last):
...
TypeError: div must be a number