On Feb 7, 2008 4:07 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > bhaaluu wrote: > > > The TDD method is the method used in my tutorial: > > Python Programming for the Absolute Beginner 2E. Michael Dawson. 2006. > > Dawson uses a very simple Tamagotchi example called Critter Caretaker > > to introduce the mechanics of POOP. However, perhaps he is using > > the TDD method of "design"? > > I don't think Dawson uses TDD. AFAIK he doesn't talk about unit-testing > at all, which is the fundamental practice of TDD. For an example of unit > tests in Python, see > http://docs.python.org/lib/minimal-example.html > > > here is > > a first little testing snippet from the testing directory, using the TDD > > method. I'm confident that if I am using the terminology incorrectly, > > someone will point out the error of my ways. > > I think you are using the terminology incorrectly. I would call this an > example of experimental programming, maybe. A classic example of TDD in > Java is here: > http://junit.sourceforge.net/doc/testinfected/testing.htm
What is the equivalent of JUnit in Python? The article says that JUnit is used for unit tests, or you can write your own. Since I don't have a clue, writing my own is probably out the question. Also I'm not familiar with Java, and am just learning Python OOP, so I'm not getting much out of that one. Sorry. Absolute Beginner here. > > > class TestClass1(object): > > """ please give me a better name""" > > def __init__(self): > > """please document me""" > > self.name = "" > > self.answer = "" > > self.strength = 20 > > self.wealth = 45 > > self.light = 0 > > self.tally = 0 > > This is a good example of a data class - a class that is just a > container for data. That is a code smell. It seems to contain unrelated > values - name and strength are attributes of the player, light is an > attribute of the environment. So it should probably be more than one > class, or, since the entire program is in one loop, these could just be > local variables of main(). Well, most of these were local variables in main() in the procedural version of this program. So DataClass() is what I should name such a class. I was wondering about that. These variables were all initialized in the procedural program before the loop started. Also, the Castle was setup as part of the initialization, but I'm not dealing with that here. I'm just trying to learn how to design here. I figured I'd put the Castle setup in it's own class because it is an object (using the "model as a real-world object" method). I don't think I can worry about whether the CodeSmells at this point. I'm thinking I need to design something that works, then be able to "refactor" it to eliminate as many CodeSmells as I can. But! Noted: a DataClass is a CodeSmell. > > > def main(): > > tc1 = TestClass1() # instance > > tc1.__init__() # invoke method > > The __init__() method is called implicitly by calling TestClass1(). > Generally the only time you explicitly call __init__() is when calling > the method of a base class. I can fix that right now! Back to the laboratory! 8^D > > Kent > Happy Programming! -- b h a a l u u at g m a i l dot c o m "You assist an evil system most effectively by obeying its orders and decrees. An evil system never deserves such allegiance. Allegiance to it means partaking of the evil. A good person will resist an evil system with his or her whole soul." [Mahatma Gandhi] _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
