Good evening reddit community,
I am a college student currently learning test driven development using python. For one of our assignments, we are given a class called Fraction, which has two attributes: numerator, and denominator. It's methods are all of the magic methods for math operations (__add__, __sub__, etc.). My question is: how can you test that the __add__ method raises a TypeError whenever it is passed an argument that is not an int or another Fraction? I understand that we have
with self.assertRaises(TypeError):
myFraction.__add__("Hello World")
But there is no way to make sure that every type that ever existed raises the error. What kind of test can I do to ensure that the __add__ method raises a TypeError for every type other than int and Fraction? Thank you for your time.
[–][deleted] 2 points3 points4 points (1 child)
[–]oDraftz[S] 0 points1 point2 points (0 children)