Attached Files: heap.py(1.81 KB) math.py(1.63 KB) In in this lab,…

Question Answered step-by-step Attached Files: heap.py(1.81 KB) math.py(1.63 KB) In in this lab,… Attached Files: heap.py (1.81 KB) math.py (1.63 KB) In in this lab, we will be developing unit tests for two simple Python modules, a heap data structure class and a math utility class (click on attached files to dowload). We will be using Python unittest framework. In addition to developing the unit tests, we will be using the “coverage” tool to generate statement coverage reports to measure code coverage.Readings:Python unittest frameworkThe coverage ToolSteps:Study attached python classes (heap.py and math.py) to get a sense of what these modules do.Study the different functions (units) in each class and design a set of test cases that would result in 100% statement coverage.Use the unittest framework to develop unit tests for each of the test cases identified in 2.Run your unit tests using the unittest runner and make sure all unit tests pass.Use the coverage tool to generate a coverage report.Deliverables:In a Word document, a table listing all functions and the test cases you identified.Python unit test code.Screenshot showing successful run of all unit tests (for Heap and Math) classes.The report generated by the coverage tool.class Heap: def __init__(self): self._heap = [0] def _swap(self, i, j): self._heap[i], self._heap[j] = self._heap[j], self._heap[i] def _last_idx(self): return len(self._heap) – 1 def _left(self, i): return i * 2 def _right(self, i): return i * 2 + 1 def _parent(self, i): return i // 2 def _has_left(self, i): return self._left(i) < len(self._heap) def _has_right(self, i): return self._right(i) < len(self._heap) def empty(self): return len(self._heap) == 1 def add(self, key): self._heap.append(key) j = self._last_idx() while j > 1 and self._heap[j] < self._heap[self._parent(j)]: self._swap(j, self._parent(j)) j = self._parent(j) def remove_min(self): if self.empty(): raise Exception() self._swap(1, self._last_idx()) result = self._heap[-1] self._heap.pop() # push new element down the heap j = 1 while True: min = j if self._has_left(j) and self._heap[self._left(j)] < self._heap[min]: min = self._left(j) if self._has_right(j) and self._heap[self._right(j)] < self._heap[min]: min = self._right(j) if min == j: #found right location for min, break break self._swap(j, min) j = min return resultdef heap_sort(l): heap = Heap() #phase I: nlogn for e in l: heap.add(e) sorted_list = [] #phase II: nlogn while not heap.empty(): sorted_list.append(heap.remove_min()) return sorted_listprint(heap_sort([3, 1, 10, 5, 0, 50])) class Math: def add(self, a: int, b: int): '''calculates and returns a plus b''' return a + b def multiply(self, a: int, b: int): '''calculates and returns a multiplied by b''' return a * b def divide(self, a: int, b: int): ''' calculates a divided by b, raises ValueError on division by Zero''' if b == 0: raise ValueError return a/b def is_even(self, a: int): return a // 2 == 0 def power(self, a: int, b: int): '''calculates a to the power of b''' prod = 1 for i in range(abs(b)): prod *= a return prod def is_prime(self, num: int): '''finds out if num is a prime or not''' if num < 0: raise(ValueError()) if num == 0: return False if num <=3: return True for i in range(2, num): if num % i == 0: return False return True def factorial(self, n: int): '''calculates n! = 1 * 2 * 3 * ... * n''' prod = 1 for i in range(1, n): prod *= i return prod def factors(number: int): '''finds and returns list of factors for number''' if number <= 0: raise ValueError('number must be geater than zero') if number == 1 or number == 2: return list(range(1, number)) factors = [1, number] for factor in range(3, number): if number % factor == 0: factors.append(factor) return factors Computer Science Engineering & Technology Software engineering ART MISC Share QuestionEmailCopy link Comments (0)

Needs help with similar assignment?

We are available 24x7 to deliver the best services and assignment ready within 3-4 hours? Order a custom-written, plagiarism-free paper

Get Answer Over WhatsApp Order Paper Now