Results 1 to 6 of 6
  1. #1
    gomdohri is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default 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;
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default 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.

  3. #3
    gomdohri is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default Re: TestCase error (AssertEquals)

    Sorry what is a boolean primitive? sorry not familar with the terminology

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: TestCase error (AssertEquals)

    Quote Originally Posted by gomdohri View Post
    Sorry what is a boolean primitive? sorry not familar with the terminology
    Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)

  5. #5
    gomdohri is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default 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?

  6. #6
    gomdohri is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 01-21-2011, 01:37 PM
  2. JUnit test - AssertEquals
    By dellacpa in forum New To Java
    Replies: 2
    Last Post: 11-21-2010, 09:19 PM
  3. JUNIT testing assertEquals function
    By Drun in forum New To Java
    Replies: 7
    Last Post: 01-22-2010, 06:08 PM
  4. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  5. Replies: 0
    Last Post: 06-26-2009, 07:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •