Create a new project in pycharm ? Add wordhistogram.py (available on the Week 10 course content page) into the project. ? Now we need to make the wordhistogram.py more testable. This can be done by converting the codes into two python files with functions: o One file is named wordcount.py, which contains: ? One function (f1) for reading a file and creating a dictionary ? One function (f2) for sorting a dictionary reversely based on count of each word o One file is named histogram.py, which contains: ? One function (f3) for converting a dictionary into a histogram. ? Write a main function and call the methods from the main function. This can be in a separate file or as part of histogram.py Task 2 – Unit Test Example 1: Word Histogram (UG: 3 marks, Master’s: 2 marks) ? Learn how to use the unit test module in Python. ? Write a program word_test.py to test the above methods with various test cases: o For f1, try empty filename and wrong file name o For f2, try input types other than dictionary, empty dictionary o How do you test f3? Write your test code. o Fix the bugs in your word histogram code Submit your wordcount.py, histogram.py, and word_test.py code. Task 3 – Unit Test Example 2: Recursion (Master’s: 1 mark) ? Two versions to calculate factorial (iterative and recursion) def iterative_factorial(n): result = 1 for i in range(2,n+1): result *= i return result def factorial(n): if n == 1: return 1 else: return n * factorial(n-1) ? Create test cases for the recursion version, and store them in factorial_test.py ? Fix the functions so they deal with invalid input
#Sales Offer!| Get upto 25% Off: