wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Test class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Test class" Watch "Test class" New topic
Author

Test class

Jim gross
Greenhorn

Joined: Sep 24, 2001
Posts: 4
Hi,
How do I write a Test class for class LinkedList?

[This message has been edited by Cindy Glass (edited September 24, 2001).]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hi Jim -
There's a couple things missing from the code; in the readIntValues() method, there's a reference to io that isn't supported anywhere else in the class. One can assume it's an InputStream or Reader, but since it isn't declared or instantiated anywhere, I can only assume "io" is supposed to be a stand-in for System.in.
On the other hand, I don't know which class (if any) allows you to prompt the user as a argument to some input type, and expect an integer in return. It's been a while since I've done any client-side java and I don't have the JDK docs at hand, so I dunno know. But we need a little more to go on here.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Jim gross
Greenhorn

Joined: Sep 24, 2001
Posts: 4
Hi Mr. Ernest,
Thank you for answering my question.
I forgot to send the rest of the code. Here they are.
public class List
{

private int element;
private List next;
public List()
{

element = 0;
next = null;
}
public List(int elem, List nextElem)
{
element = elem;
next = nextElem;
}
public void setElem(int someElement)
{
element = someElement;
}
public void setNext(List newNext)
{
next = newNext;
}
public int getElem()
{
return element;
}
public List getNext()
{
return next;
}
}
public class io
{
public io()
{
}

static String readString()
{ int ch;
String r = "";
boolean done = false;
while (!done)
{ try
{ ch = System.in.read();
if (ch < 0 | | (char)ch == '\n')
done = true;
else if ((char)ch != '\r')
r = r + (char) ch;
}
catch(java.io.IOException e)
{ done = true;
}
}
return r;
}


static void printPrompt(String prompt)
{ System.out.print(prompt + " ");
System.out.flush();
}


static int readInt(String prompt)
{ while(true)
{ printPrompt(prompt);
try
{ return Integer.valueOf
(readString().trim()).intValue();
} catch(NumberFormatException e)
{ System.out.println
("Not an integer. Please try again!");
}
}
}

static void error(String err)
{
throw new Error(err);
}

}
Jamie Young
Ranch Hand

Joined: Jun 19, 2001
Posts: 31
Have you considered using the LinkedList class java.util.LinkedList? I would test your program against it. After all it is a concrete collection. It is easy to use.
------------------
Jim gross
Greenhorn

Joined: Sep 24, 2001
Posts: 4
But I still don't know how to write a test class.
How do I start?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You can just add a main() method to your LinkedList class and work with it.
Or you can create a separate class Test that has the main and use it to test your stuff.

[This message has been edited by Cindy Glass (edited September 25, 2001).]


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Test class