In this project, I started practicing test-driven development using docstring
and unittest
in Python.
- tests: Folder of test files. Includes both Holberton-provided ones as well as the following eight independently-developed:
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): |
100-matrix_mul.py |
def matrix_mul(m_a, m_b): |
101-lazy_matrix_mul.py |
def lazy_matrix_mul(m_a, m_b): |
102-python.c |
void print_python_string(PyObject *p); |
-
0. Integers addition
- 0-add_integer.py: Python function that returns the integer addition of two numbers.
- If either of
a
orb
is not anint
orfloat
, aTypeError
is raised with the messagea must be an integer
orb must be an integer
. - If either of
a
orb
is afloat
, it is casted to anint
before 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
matrix
bydiv
. - Quotients are rounded to two decimal places.
- If
matrix
is not a list of lists ofint
s orfloat
s, aTypeError
is raised with the messagematrix must be a matrix (list of lists) of integers/floats
. - If
matrix
contains rows of different lengths, aTypeError
is raised with the messageEach row of the matrix must have the same size
. - If the divisor
div
is not anint
orfloat
, aTypeError
is raised with the messagediv must be a number
. - If
div
is0
, aZeroDivisionError
is 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_name
orlast_name
is not astr
, aTypeError
is raised with the messagefirst_name must be a string
orlast_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
size
represents the height/width of the square. - If
size
is not anint
, aTypeError
is raised with the message,size must be an integer
. - If
size
is less than0
, aValueError
is 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
text
is not astr
, aTypeError
is raised with the messagetext must be a string
. - No spaces are printed at the beginning or end of each printed line.
-
5. Max integer - Unittest
- tests/6-max_integer_test.py: Python class/scriptthat runs unittests for the function
def max_integer(list=[]):
.
- tests/6-max_integer_test.py: Python class/scriptthat runs unittests for the function
-
6. Matrix multiplication
- 100-matrix_mul.py: Python function that multiplies two matrices.
- Returns a new matrix representing the multiplication of
m_a
bym_b
. - If either of
m_a
orm_b
is empty (ie.== []
or== [[]]
), aValueError
is raised with the messagem_a can't be empty
orm_b can't be empty
. - If either of
m_a
orm_b
is not a list, aTypeError
is raised with the messagem_a must be a list
orm_b
must be a list. - If either of
m_a
orm_b
is not a list of lists, aTypeError
is raised with the messagem_a must be a list of lists
orm_b must be a list of lists
. - If either of
m_a
orm_b
is not a list of lists ofint
s orfloat
s, aTypeError
is raised with the messagem_a should contain only integers or floats
orm_b should contain only integers or floats
. - If either of
m_a
orm_b
contains rows of different lengths, aTypeError
is raised with the messageeach row of m_a must should be of the same size
oreach row of m_b must should be of the same size
. - If
m_a
andm_b
cannot be multiplied (ie. row size ofm_a
does not match column size ofm_b
), aValueError
is raised with the messagem_a and m_b can't be multiplied
.
-
7. Lazy matrix multiplication
- 101-lazy_matrix_mul.py: Python function that multiplies two matrices using the module
NumPy
. - Identical in function to 100-matrix_mul.py.
- 101-lazy_matrix_mul.py: Python function that multiplies two matrices using the module
-
8. CPython #3: Python Strings
- 102-python.c: C function that prints basic information about Python string objects.