Skip to content

Commit

Permalink
Added JUnits
Browse files Browse the repository at this point in the history
  • Loading branch information
xingxinggeng committed Mar 1, 2018
1 parent 757ad4e commit 6d4ff7b
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 116 deletions.
125 changes: 74 additions & 51 deletions src/edu/ucsb/cs56/projects/games/pong/tests/BallTest.java
Original file line number Diff line number Diff line change
@@ -1,73 +1,96 @@
package edu.ucsb.cs56.projects.games.pong.tests;

import edu.ucsb.cs56.projects.games.pong.gameplay.Ball;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

/**
* The test class BallTest to test the class Ball
*
* @author Timothy Fok
* @version CS56, Spring 2012, cp1 05.18.12
* @version CS56, Spring 2012, cp1 05.18.12
* @author Samuel Fu, Xingxing Geng
* @version CS56, Winter 2018
* @see Ball
*/

public class BallTest
{
/**Default BallTest constructor*/
public BallTest() {}
public BallTest(){}

/**
test constructor from BallTest
//@see Ball
*/
/*
@Test public void testConstructor()
{
Ball ball = new Ball(20,20,20,20);
assertEquals(20,ball.getXpos());
assertEquals(20,ball.getYpos());
}*/

/**
test constructor again from BallTest
// @see Ball
*/
/*
@Test public void testConstructor2()
@Test public void testConstructor_1()
{
Ball ball = new Ball(30,100,20,20);
assertEquals(30,ball.getXpos());
assertEquals(100,ball.getYpos());
Ball ball = new Ball(20,20,20,20,false);
assertEquals(20,ball.getWidth());
assertEquals(20,ball.getHeight());
}

@Test public void testConstructor_2()
{
Ball ball = new Ball(0,0,30,30,true);
assertEquals(0,ball.getXCoordinate());
assertEquals(0,ball.getYCoordinate());
}
*/

/**
test getdx
// @see Ball#getdx
*/
/*
@Test public void testgetdx()
{
Ball ball = new Ball(30,100,20,20);
ball.setdx(5);
assertEquals(5,ball.getdx());
}
*/
/**
test getdy
// @see Ball#getdy
*/
/*
@Test public void testgetdy()
{
Ball ball = new Ball(30,100,20,20);
ball.setdy(7);
assertEquals(7,ball.getdy());

@Test public void testConstructor_4()
{
Ball ball = new Ball(0,0,30,30,true);
assertEquals(-1,ball.getSpeed());
}

@Test public void testConstructor_3()
{
Ball ball = new Ball(0,0,30,30,true);
assertEquals(-1,ball.getSpeed());
}

private Ball b1 = new Ball(0,0,30,30,false);
private Ball b2 = new Ball(200,200,30,30,false);
private Ball b3 = new Ball(100,50,20,20,true);
private Ball b4 = new Ball(50,100,20,30,true);

@Test public void testgetYVelocity()
{
b1.setYVelocity(5);
b2.setYVelocity(10);
assertEquals(5,b1.getYVelocity());
assertEquals(10,b2.getYVelocity());
}

@Test public void testisAttached()
{
b1.setAttached(false);
b2.setAttached(true);
assertEquals(false,b1.isAttached());
assertEquals(true,b2.isAttached());
}

@Test public void testgetSpeed()
{
b1.setSpeed(5);
b2.setSpeed(10);
assertEquals(5,b1.getSpeed());
assertEquals(10,b2.getSpeed());
}

@Test public void testgetBallLost()
{
b1.setBallsLost(2);
b2.setBallsLost(1);
assertEquals(2,b1.getBallsLost());
assertEquals(1,b2.getBallsLost());
}

@Test public void testBallAttachUpdate()
{
b1.setAttached(true);
b2.setAttached(true);
b1.ballAttachUpdate();
b2.ballAttachUpdate();
assertEquals(0,b1.getYVelocity());
assertEquals(0,b2.getYVelocity());
}
*/


}
100 changes: 65 additions & 35 deletions src/edu/ucsb/cs56/projects/games/pong/tests/PaddleTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package edu.ucsb.cs56.projects.games.pong.tests;

import edu.ucsb.cs56.projects.games.pong.gameplay.Paddle;
import edu.ucsb.cs56.projects.games.pong.gameplay.Paddle;
import edu.ucsb.cs56.projects.games.pong.gameplay.Ball;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

/**
* The test class PaddleTest to test the class Paddle
*
* @author Timothy Fok
* @version CS56, Spring 2012, cp1 05.18.12
* @version CS56, Spring 2012, cp1 05.18.12
* @author Samuel Fu, Xingxing Geng
* @version CS56, Winter 2018
* @see Paddle
*/

Expand All @@ -22,41 +25,68 @@ public PaddleTest() {}
* @see Paddle
*/
@Test
public void testConstructor(){
public void testConstructor_1(){
Paddle paddle = new Paddle(20,20, 90, 1);
assertEquals(20,paddle.getXCoordinate());
assertEquals(20,paddle.getYCoordinate());
}

//=======
/* @Test public void testConstructor(){
Paddle paddle = new Paddle(20,20, 90);
assertEquals(20,paddle.getXCoordinate());
assertEquals(20,paddle.getYCoordinate());
}*/
//>>>>>>> c0718998d42ee9377f73c5840fd8eb88a156ccb7

/**
* test constructor from PaddleTest
* @see Paddle
*/
/*@Test public void testConstructor2(){
Paddle paddle = new Paddle(30,100, 90);
assertEquals(30,paddle.getXpos());
assertEquals(100,paddle.getYpos());
}*/

//////////////////////////////////
// not needed
// changed to getYVelocity()
// setYVelocity( int dy )
/**
test getdy
//@see Paddle#getdy
*/
/* @Test public void testgetdy(){
Paddle paddle = new Paddle(30,100, 90);
paddle.setdy(7);
assertEquals(7,paddle.getdy());
}*/

@Test
public void testConstructor_2(){
Paddle paddle = new Paddle(50,50, 90, 1,false);
assertEquals(50,paddle.getXCoordinate());
assertEquals(50,paddle.getYCoordinate());
}

private Paddle p1 = new Paddle(30,30,50,2);
private Paddle p2 = new Paddle(15,15,30,3);
private Paddle p3 = new Paddle(40,40,90,4);
private Paddle p4 = new Paddle(25,25,50,5,true);
private Paddle p5 = new Paddle(30,30,100,0,false);

/* @Test
public void decrementBall(){
p1.decrementBalls();
assertEquals(1,p1.ballCount);
}*/

@Test
public void testIncrementPoint(){
p1.incrementPoints(5);
assertEquals(5,p1.getPoints());
}

@Test
public void testIncrementPoint_2(){
p2.incrementPoints(0);
assertEquals(0,p2.getPoints());
}

@Test
public void testIncrementPoint_onRight(){
p5.incrementPoints(10);
assertEquals(10,p5.getPoints());
}

@Test
public void testIncrementPoint_onRight_2(){
p4.incrementPoints(20);
assertEquals(20,p4.getPoints());
}

@Test
public void testPlayerMissing(){
Ball b = new Ball(10,10,20,20,true);
p1.playerMissed(b,10,p5);
assertEquals(10,p5.getPoints());
}

@Test
public void testPlayerMissing_2(){
Ball b = new Ball(20,20,40,40,false);
p2.playerMissed(b,10,p4);
assertEquals(10,p4.getPoints());
}


}
103 changes: 73 additions & 30 deletions src/edu/ucsb/cs56/projects/games/pong/tests/PongTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package edu.ucsb.cs56.projects.games.pong.tests;

import edu.ucsb.cs56.projects.games.pong.gameplay.Pong;

import edu.ucsb.cs56.projects.games.pong.gameplay.Pong;
import edu.ucsb.cs56.projects.games.pong.gameplay.Ball;
import edu.ucsb.cs56.projects.games.pong.gameplay.Paddle;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

/**
* The test class PongTest to test the class Pong
*
* @author Jake Dumont, Heneli Kailahi
* @version CS56, Spring 2013, CS56-Games-Pong
* @version CS56, Spring 2013, CS56-Games-Pong
* @author Samuel Fu, Xingxing Geng
* @version CS56, Winter 2018
* @see Pong
*/
public class PongTest
Expand All @@ -19,36 +23,75 @@ public PongTest() {}
/**
* test constructor from Pong
* @see Pong
*/
/*@Test
*/
private Paddle p1 = new Paddle(30,30,50,2);
private Paddle p2 = new Paddle(15,15,30,3);
private Paddle p3 = new Paddle(40,40,90,4);
private Paddle p4 = new Paddle(25,25,50,5);
private Paddle p5 = new Paddle(30,30,100,0,false);

private Ball b1 = new Ball(0,0,30,30,false);
private Ball b2 = new Ball(200,200,30,30,false);
private Ball b3 = new Ball(100,50,20,20,true);
private Ball b4 = new Ball(50,100,20,30,true);

@Test
public void testConstructor()
{
Pong game = new Pong();
Paddle pp = new Paddle(8, 160);
Ball bb = new Ball(300, 300, 20, 20);
assertEquals(pp.getXpos(),game.p1.getXpos());
assertEquals(pp.getYpos(),game.p1.getYpos());
Paddle pp = new Paddle(30,30,50,2);
Ball bb = new Ball(0,0,30,30,false);

assertEquals(bb.getXpos(), game.b.getXpos());
assertEquals(bb.getYpos(), game.b.getYpos());
}*/

assertEquals(pp.getXCoordinate(),30);
assertEquals(pp.getYCoordinate(),30);
}

@Test
public void testgetHits()
{
Pong game = new Pong();
game.hitsReset();
assertEquals(0,game.getHits());
}

@Test
public void testhitReset()
{
Pong game = new Pong();
game.hitsReset();

assertEquals(0,game.getHits());
}

@Test
public void testincrementHits()
{
Pong game = new Pong();
game.hitsReset();
game.incrementHits();
assertEquals(1,game.getHits());
}

@Test
public void testsetwinner()
{
Pong game = new Pong();
game.setWinner(p1);
assertEquals(p1,game.getWinner());
}

@Test
public void testgetPlayer1()
{
Pong game = new Pong();
assertEquals(p1,game.getPlayer1());
}

@Test
public void testgetPlayer2()
{
Pong game = new Pong();
assertEquals(p2,game.getPlayer2());
}

//////////////////////////////////////////////
// tests the incrementor
// for loop
////////////////////////////////
/**
* test getPoints
* @see Pong#getPoints
*/
/*
@Test public void testgetHits()
{
Pong game = new Pong();
game.setPoints(5);
assertEquals(5,game.getPoints());
}
*/
}

0 comments on commit 6d4ff7b

Please sign in to comment.