Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kachary3
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
kalpana acharya
kachary3
Commits
13c3b093
Commit
13c3b093
authored
9 months ago
by
kalpana acharya
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests to detect assignment errors
parent
535b1581
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+37
-3
37 additions, 3 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
37 additions
and
3 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
37
−
3
View file @
13c3b093
...
...
@@ -2,8 +2,6 @@ package dotsandboxes;
import
org.junit.jupiter.api.*
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assumptions
.*;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
...
...
@@ -27,5 +25,41 @@ public class DotsAndBoxesGridTest {
assertTrue
(
true
);
}
// FIXME: You need to write tests for the two known bugs in the code.
// Test cases for known bugs
@Test
public
void
testSquareCompletionBug
()
{
logger
.
info
(
"Testing square completion logic"
);
// Create a new game grid
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
();
// Draw lines to form a square
grid
.
drawLine
(
0
,
0
,
0
,
1
);
// Top horizontal line
grid
.
drawLine
(
0
,
0
,
1
,
0
);
// Left vertical line
grid
.
drawLine
(
0
,
1
,
1
,
1
);
// Bottom horizontal line
grid
.
drawLine
(
1
,
0
,
1
,
1
);
// Right vertical line
// Test if the square at (0, 0) is complete
boolean
isComplete
=
grid
.
isSquareComplete
(
0
,
0
);
// The bug is that isSquareComplete always returns true
assertFalse
(
isComplete
,
"The square completion check should fail because the method is broken."
);
}
@Test
public
void
testDrawLineTwiceThrowsException
()
{
logger
.
info
(
"Testing drawing the same line twice throws exception"
);
// Create a new game grid
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
();
// Draw a line once
grid
.
drawLine
(
0
,
0
,
0
,
1
);
// Attempt to draw the same line again
assertThrows
(
IllegalStateException
.
class
,
()
->
{
grid
.
drawLine
(
0
,
0
,
0
,
1
);
},
"Drawing the same line twice should throw IllegalStateException."
);
}
}
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