Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brick-breaker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mkandel2
brick-breaker
Commits
641c1816
Commit
641c1816
authored
1 year ago
by
abhatta5
Browse files
Options
Downloads
Patches
Plain Diff
Add Test for Ball class
parent
fe072ea9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/brickbreaker/Ball.java
+2
-2
2 additions, 2 deletions
app/src/main/java/brickbreaker/Ball.java
app/src/test/java/brickbreaker/BallTest.java
+115
-0
115 additions, 0 deletions
app/src/test/java/brickbreaker/BallTest.java
with
117 additions
and
2 deletions
app/src/main/java/brickbreaker/Ball.java
+
2
−
2
View file @
641c1816
...
...
@@ -47,8 +47,8 @@ public class Ball {
public
void
checkForWallCollisions
()
{
if
(
position
.
x
<=
0
)
{
// Left wall collision
position
.
x
=
0
;
// Set the ball at the left edge
direction
.
x
=
Math
.
abs
(
direction
.
x
);
// Reverse the x direction
position
.
x
=
0
;
// Set the ball at the left edge
direction
.
x
=
Math
.
abs
(
direction
.
x
);
// Reverse the x direction
}
if
(
position
.
x
+
radius
>=
680
)
{
// Right wall collision
...
...
This diff is collapsed.
Click to expand it.
app/src/test/java/brickbreaker/BallTest.java
0 → 100644
+
115
−
0
View file @
641c1816
package
brickbreaker
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
java.awt.Color
;
import
java.awt.Graphics
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
mockito
.
Mockito
.*;
public
class
BallTest
{
@Mock
private
Graphics
mockGraphics
;
private
Ball
ball
;
@BeforeEach
public
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
ball
=
new
Ball
(
100
,
100
,
2
,
2
,
10
,
Color
.
RED
);
}
@Test
public
void
testGetPosition
()
{
assertEquals
(
100
,
ball
.
getPosition
().
x
);
assertEquals
(
100
,
ball
.
getPosition
().
y
);
}
@Test
public
void
testGetRadius
()
{
assertEquals
(
10
,
ball
.
getRadius
());
}
@Test
public
void
testGetColor
()
{
assertEquals
(
Color
.
RED
,
ball
.
getColor
());
}
@Test
public
void
testGetDirection
()
{
assertEquals
(
2
,
ball
.
getDirection
().
x
);
assertEquals
(
2
,
ball
.
getDirection
().
y
);
}
@Test
public
void
testSetPosition
()
{
ball
.
setPosition
(
200
,
200
);
assertEquals
(
200
,
ball
.
getPosition
().
x
);
assertEquals
(
200
,
ball
.
getPosition
().
y
);
}
@Test
public
void
testSetDirection
()
{
ball
.
setDirection
(
3
,
3
);
assertEquals
(
3
,
ball
.
getDirection
().
x
);
assertEquals
(
3
,
ball
.
getDirection
().
y
);
}
@Test
public
void
testMove
()
{
ball
.
move
();
assertEquals
(
102
,
ball
.
getPosition
().
x
);
assertEquals
(
102
,
ball
.
getPosition
().
y
);
}
@Test
public
void
testCheckForWallCollisions
()
{
// Simulate a collision with the right wall
ball
.
setPosition
(
680
,
100
);
ball
.
checkForWallCollisions
();
assertEquals
(
670
,
ball
.
getPosition
().
x
);
assertEquals
(
100
,
ball
.
getPosition
().
y
);
assertEquals
(-
2
,
ball
.
getDirection
().
x
);
assertEquals
(
2
,
ball
.
getDirection
().
y
);
// Simulate a collision with the top wall
ball
.
setPosition
(
100
,
0
);
ball
.
checkForWallCollisions
();
assertEquals
(
100
,
ball
.
getPosition
().
x
);
assertEquals
(
0
,
ball
.
getPosition
().
y
);
assertEquals
(
2
,
ball
.
getDirection
().
y
);
// Simulate a collision with the left wall
ball
.
setPosition
(-
10
,
100
);
ball
.
checkForWallCollisions
();
assertEquals
(
0
,
ball
.
getPosition
().
x
);
assertEquals
(
100
,
ball
.
getPosition
().
y
);
assertEquals
(
2
,
ball
.
getDirection
().
x
);
assertEquals
(
2
,
ball
.
getDirection
().
y
);
}
@Test
public
void
testDraw
()
{
// Mock the Graphics object
ball
.
draw
(
mockGraphics
);
// Verify that setColor and fillOval are called on the mockGraphics
verify
(
mockGraphics
).
setColor
(
Color
.
RED
);
verify
(
mockGraphics
).
fillOval
(
100
,
100
,
10
,
10
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment