Results 1 to 6 of 6
Thread: TestCase error (AssertEquals)
- 09-19-2011, 03:00 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
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 #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
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).
Last edited by doWhile; 09-19-2011 at 03:45 AM.
- 09-19-2011, 03:49 AM #3
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
Re: TestCase error (AssertEquals)
Sorry what is a boolean primitive? sorry not familar with the terminology
- 09-19-2011, 03:58 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
Re: TestCase error (AssertEquals)
- 09-19-2011, 04:15 AM #5
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
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 #6
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
Similar Threads
-
Junit3 error: Implicit super constructor TestCase() is not visible
By albertkao in forum Advanced JavaReplies: 3Last Post: 01-21-2011, 01:37 PM -
JUnit test - AssertEquals
By dellacpa in forum New To JavaReplies: 2Last Post: 11-21-2010, 09:19 PM -
JUNIT testing assertEquals function
By Drun in forum New To JavaReplies: 7Last Post: 01-22-2010, 06:08 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
Getting Error while running Junit testcase in Eclipse
By Indu in forum EclipseReplies: 0Last Post: 06-26-2009, 07:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks