Take a look at the code for this simple class, and use it to figure out the answers to the questions. It's okay to check back through the book. This is just a way for you to make sure you're ready to move on:
class ClassOne: def __init__(self, arg1, arg2): self.arg1 = int(arg1) self.arg2 = arg2 def method1(self, x): return x * self.arg1 def method2(self, x): return self.method1(self.arg2) * x
Here are the questions:
Answer: There are three units that exist in the preceding code and that are as follows: __init__
, method1
, and method2
. __init__
is a method, just as method1
and method2
. The fact that it's a constructor means that it's all tangled up with the other units, but it's still a method containing code and a possible location for bugs, and so we cannot afford to treat this as anything other than a unit.
Answer: Both method1
and method2
assume that __init__
works right, and method2
makes the same assumption as that of method1
.
method2
that does not assume that other units work correctly?Answer: The tests for method2
will need to use a fake method1
that is a part of the test code, and not a part of the code being tested.
3.145.202.61