Stefan Evans wrote:Here is one example to demonstrate at least the idea.
I'm going to do it as a JUnit test, but it should at least explain the gist of it.
That explains one simple test case.
What other cases could you test? What happens if you pass an empty array? What about the array [3,2,1]
Edit: @Junilu. Just one example can't hurt can it?
Paul Clapham wrote:Well, just for example, you might first set an array into an instance of your class. Then you might call the isInIncreasingOrder method on that instance and see if it returns the right value. The "right" value would of course depend on what values were in the array you passed to the instance. So you would try this with an array which is in increasing order, and then with one which isn't in increasing order, and see if isInIncreasingOrder() returns "true" for the first and "false" for the second.
I expect this is already clear to you, but the code you're going to write in the Array class has a purpose and the tests you write are supposed to find out whether the code actually fits that purpose.
Campbell Ritchie wrote:You are creating a new instance of your class, then calling its methods in turn. Obviously you will have different methods in your class.
You should override the toString method so you get a decent printout from println. You can read about toString in lots of places; this sample chapter from Joshua Bloch's Effective Java™ is one of them.
Jesper de Jong wrote:If you're not going to use a testing framework like JUnit, then what you have to do is just create a new class named TestArray with a public static void main(String[] args) method.
In there, you can create new instances of your Array class and call methods on it and print out the results, so that you can see if it works as you intended.