Module 3
Object Oriented Programming
Unit 9
Packaging and Testing
Learning Outcomes
- Appropriately package a Python code development.
- Adequately and effectively document your code.
- Use the tools available in Python to test the quality of code.
e-Portfolio Activities
Activity 1
Extend the following program to test accuracy of operations using the assert statement.
# Python String Operations
str1 = 'Hello'
str2 = 'World!'
# using +
print('str1 + str2 = ', str1 + str2)
# using *
print('str1 * 3 =', str1 * 3)
Code:
# Required variables
str1 = 'Hello'
str2 = 'World!'
# using +
result_concat = str1 + str2
print('str1 + str2 =', result_concat)
expected_concat = ''.join([str1, str2])
assert result_concat == expected_concat, f"Assertion failed. Expected: {
expected_concat}, Actual: {result_concat}"
# using *
result_repeat = str1 * 3
print('str1 * 3 =', result_repeat)
expected_repeat = ''.join([str1 for _ in range(3)])
assert result_repeat == expected_repeat, f"Assertion failed. Expected: {
expected_repeat}, Actual: {result_repeat}"
Reflection
- During the holiday season, I took a break from work and studies. Upon returning, I prioritised reviewing lecturecasts, readings, and completing formative activities for the remaining units. This allowed me to dedicate more time to preparing for the assignments in Units 11 and 12.