In this project, I started practicing test-driven development using docstringand unittest in Python.
Prototypes for functions written in this project:
| File | Prototype |
|---|---|
0-add_integer.py |
def add_integer(a, b=98): |
2-matrix_divided.py |
def matrix_divided(matrix, div): |
3-say_my_name.py |
def say_my_name(first_name, last_name=""): |
4-print_square.py |
def print_square(size): |
5-text_indentation.py |
def text_indentation(text): |
-
0. Integers addition
- 0-add_integer.py: Python function that returns the integer addition of two numbers.
- If either of
aorbis not anintorfloat, aTypeErroris raised with the messagea must be an integerorb must be an integer. - If either of
aorbis afloat, it is casted to anintbefore addition.
-
1. Divide a matrix
- 2-matrix_divided.py: Python function that divides all elements of a matrix by a common divisor.
- Returns a new matrix representing the division of all elements of
matrixbydiv. - Quotients are rounded to two decimal places.
- If
matrixis not a list of lists ofints orfloats, aTypeErroris raised with the messagematrix must be a matrix (list of lists) of integers/floats. - If
matrixcontains rows of different lengths, aTypeErroris raised with the messageEach row of the matrix must have the same size. - If the divisor
divis not anintorfloat, aTypeErroris raised with the messagediv must be a number. - If
divis0, aZeroDivisionErroris raised with the messagedivision by zero.
-
2. Say my name
- 3-say_my_name.py: Python function that prints a name in the format
My name is <first_name> <last_name>. - If either of
first_nameorlast_nameis not astr, aTypeErroris raised with the messagefirst_name must be a stringorlast_name must be a string.
- 3-say_my_name.py: Python function that prints a name in the format
-
3. Print square
- 4-print_square.py: Python function that prints a square using the
#character. - The paramter
sizerepresents the height/width of the square. - If
sizeis not anint, aTypeErroris raised with the message,size must be an integer. - If
sizeis less than0, aValueErroris raised with the messagesize must be >= 0.
- 4-print_square.py: Python function that prints a square using the
-
4. Text indentation
- 5-text_indentation.py: Python function that prints text with indentation.
- Two new lines are printed after any
.,?, or:character. - If
textis not astr, aTypeErroris raised with the messagetext must be a string. - No spaces are printed at the beginning or end of each printed line.
