# TestCase error (AssertEquals)

• 09-19-2011, 03:00 AM
gomdohri
TestCase error (AssertEquals)
I'm testing whether my collision method works or not and the mechanism I want will use is that I will randomize the position of the ball and the wall (both of them having same position but in different position of course) and using for loop run it 1000 times and if no mistake then fine.

But in assertEquals, it gives an error like this :
'The method assertEquals(Object, Object) is ambiguous for the type GameCompTest. What is wrong with mine?

GameCompTest.java
===================
package TestTeeter;

import junit.framework.TestCase;
import java.util.Random;

public class GameCompTest extends TestCase{

private double xv, yv;

public void testBallCollideWithWall(){
for(int i = 0; i < 1000; i++){
Random ran = new Random();

xv = ran.nextDouble();
yv = ran.nextDouble();

Ball b = new Ball(xv,yv,40,40);
Wall w = new Wall(xv,yv);

assertEquals(true,b.collide(w));
}
}
}
=================
Collide function ( in different class)
public Boolean collide(Body b) { // This determines if two bodies have collided.
if(!((b.x + width()/2) <= x - b.width()/2)
&&!((b.x - width()/2 >= x + b.width()/2))
&&!((b.y + height()/2 <= y - b.height()/2))
&&!((b.y - height()/2 >= y + b.height()/2))){
return true;
}
else
return false;
}
================
Ball constructor in Ball.java

public Ball(double xp, double yp, double horizontal, double vertical) {
x = xp;
y = yp;
speedx = horizontal;
speedy = vertical;

}

===================
Wall Constructor in Wall.java

// x value represents the horizontal position of the wall
// y value represents the vertical position of the wall

public Wall(Double xp, Double yp) {
x = xp;
y = yp;
}
• 09-19-2011, 03:43 AM
doWhile
Re: TestCase error (AssertEquals)
The assertEquals method is overloaded. In the context you use the method, you pass a boolean primitive and a Boolean object, which is ambiguous as to which definition of the method should be used. One option would be to have collide return a boolean primitive (unless you must return an instance of the boolean wrapper class for other reasons).
• 09-19-2011, 03:49 AM
gomdohri
Re: TestCase error (AssertEquals)
Sorry what is a boolean primitive? sorry not familar with the terminology
• 09-19-2011, 03:58 AM
doWhile
Re: TestCase error (AssertEquals)
Quote:

Originally Posted by gomdohri
Sorry what is a boolean primitive? sorry not familar with the terminology

Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
• 09-19-2011, 04:15 AM
gomdohri
Re: TestCase error (AssertEquals)
public Boolean collide(Body b) { // This determines if two bodies have collided.
return !((b.x + width()/2) <= x - b.width()/2)
&&!((b.x - width()/2 >= x + b.width()/2))
&&!((b.y + height()/2 <= y - b.height()/2))
&&!((b.y - height()/2 >= y + b.height()/2));
}
....hm.. I did upto this far but I am not too sure how to I return a boolean primitive;;

I have simplified up to this far... but primitive means that boolean ______ =true according to the article above. How should I convert this to primitive type?
• 09-19-2011, 06:20 AM
gomdohri
Re: TestCase error (AssertEquals)
Don't worry