Michelle Loh
Posts: 10
Nickname: modernage
Registered: Feb, 2006
confused about writing test driver
Posted: Mar 5, 2006 11:55 PM
Advertisement
Hi, I want to test my code with a driver but i am not exactly sure on how to write one for this, can anyone give me an example to write one for a certain part of the code? public class Window { private int top,left,width,height,x,y,amount,screenwidth,screenheight,horizontal,vertical,b ottomx,bottomy,othertop,otherbottomx,otherbottomy,otherleft;public Window(int top, int left, int width, int height)
{
this.top=top;
this.left=left;
this.width=width;
this.height=height;
}
public int getTop()
{
return top;
}
public int getLeft()
{
return left;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public void moveTo(int x, int y)
{
left=x;
top=y;
}
public boolean resizeHorizontally(int amount)
{
horizontal=amount+width;
if (horizontal<0)
{
return false ;
}
width=width+amount;
return true ;
}
public boolean resizeVertically(int amount)
{
vertical=amount+height;
if (vertical<0)
{
return false ;
}
height=height+amount;
return true ;
}
public boolean contains(int x, int y)
{
bottomx=left+width-1;
bottomy=top+height-1;
if (x>=left && x<=bottomx && y>=top && y<=bottomy)
{
return true ;
}
return false ;
}
public boolean isCompletelyOnscreen(int screenwidth, int screenheight)
{
bottomx=left+width-1;
bottomy=top+height-1;
screenwidth=screenwidth-1;
screenheight=screenheight-1;
if (left>=0 && left<=screenwidth && top>=0 && top<=screenheight && bottomx>=0 && bottomx<=screenwidth && bottomy>=0 && bottomy<=screenheight)
{
return true ;
}
return false ;
}
public boolean overlaps(Window other)
{
otherleft=other.getLeft();
othertop=other.getTop();
otherbottomx=other.getLeft()+other.getWidth()-1;
otherbottomy=other.getTop()+other.getHeight()-1;
if (otherbottomx>=left && otherbottomx<=bottomx && othertop<=bottomy && otherbottomy>=top)
{
return true ;
}
if (otherleft>=left && otherleft<=bottomx && othertop<=bottomy && otherbottomy>=top)
{
return true ;
}
if (otherbottomx>=left && otherbottomx<=bottomx && othertop<=bottomy && otherbottomy>=bottomy)
{
return true ;
}
if (otherleft>=left && otherleft<=bottomx && othertop<=bottomy && otherbottomy>=bottomy)
{
return true ;
}
return false ;
}
}