Question: ****PYTHON CODING UNIT TESTS: Implement each of the named test methods provided in the tests.py. Then think of and implement 2 more test methods that
****PYTHON CODING UNIT TESTS: Implement each of the named test methods provided in the tests.py. Then think of and implement 2 more test methods that help define the behavior of Fraction's __init__ or __str__. ****
test.py :
from fraction import Fraction import unittest class TestInit(unittest.TestCase): #you should inspect the data members of self here, don't use __str__ #several of these will need to check to see if an exception is raised def test_divZero(self): with self.assertRaises(ZeroDivisionError,msg="Denominator of zero fails to raise DivByZero"): a = Fraction(1,0) def test_default(self): pass def test_oneArg(self): pass def test_twoArg(self): pass def test_threeArg(self): pass def test_invalidArg(self): pass def test_negDenom(self): pass def test_reduced(self): pass class TestStr(unittest.TestCase): def test_displayfraction(self): a = Fraction(1,2) self.assertEqual(" 1/2 ",a.__str__()) def test_displayInt(self): pass def test_displayNeg(self): pass fraction.py:
class Fraction(object): """Reduced fraction class with integer numerator and denominator.""" def __init__(self, numerator=0, denominator=1): #precondition: if provided, numerator and denominator are integers, denominator is not 0 #postcondition: self.numerator and self.denominator are stored in reduced terms, with the gcd removed #if both arguments are negative, signs cancel and self.numerator, self.denominator will both be positive #if denominator is negative and numerator is positive, move the sign to self.numerator; self.denominator #should always be positive. pass def __str__(self): #precondition: self is valid #postcondition: return "/" unless the denominator is 1, then return # pass
Step by Step Solution
There are 3 Steps involved in it
To implement the unit tests for the Fraction class in Python we will complete each test method with specific checks and assertions We will examine the init and str methods to ensure they behave as exp... View full answer
Get step-by-step solutions from verified subject matter experts
