This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello guys and I hope that you are doing well. I have written a program that creates a class and then I have created a test program. I would be gratefull if you could look at it and critique. Any suggestions as how to improve it would be welcome. I still have to finish commenting so that part is still rough. Thanks for your help NN
Now for the test program!
I know that this long. Is there a way to compress it? What observations do you have? Thank you for your time and help NN [ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ April 04, 2004: Message edited by: Dirk Schreckmann ]
Howdy pardner. Let's see... Use ubb code tags around your code in future as it makes it easier to read. Method names should be actions, so setSecondNumber() is better than secondNumber() The body of getAverage() could be written as return (firstTest+secondTest)/2; There are many typographical errors and some cut and paste errors - the compiler will tell you where.
A class and a test class are a great pairing. What a great habit to get into from the start! I'd guess this is for school work - if so your instructor is giving you some good ideas. Here's a neat way to write tests so you don't have to examine the results closely by eye every time you run:
Now your tests just print a "." if they work, but give you a neat report if they fail. One note, see how I had to turn the double result into a string with ""+method(). That's a little kludgey and a bit hard to predict. You might prefer another assertEquals method that takes two doubles as arguments. This style comes from a test package called JUnit. It's maybe a bit advanced right now, but if you get into writing classes and tests (or tests BEFORE the classes!) you'll love it when you get to it.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi