Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Dots and Boxes
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anudip Chauhan
Dots and Boxes
Commits
aeec4f07
Commit
aeec4f07
authored
11 months ago
by
Anudip Chauhan
Browse files
Options
Downloads
Patches
Plain Diff
add unit tests
parent
517b89de
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+35
-0
35 additions, 0 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
35 additions
and
0 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
35
−
0
View file @
aeec4f07
...
...
@@ -28,4 +28,39 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public
void
testBoxCompletionDetection
()
{
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
4
,
3
,
2
);
/
Draw
only
three
sides
of
a
box
(
not
completing
it
)
grid
.
drawHorizontal
(
0
,
0
,
1
);
// Top
grid
.
drawVertical
(
0
,
0
,
1
);
// Left
grid
.
drawHorizontal
(
0
,
1
,
1
);
// Bottom
// Check if the box at (0, 0) is incorrectly identified as completed
assertTrue
(
grid
.
boxComplete
(
0
,
0
),
"The box should not be completed."
);
}
@Test
public
void
testBoxComplete
()
{
// Draw lines around a box and check if it's completed
game
.
drawHorizontal
(
0
,
0
,
1
);
// Top horizontal line
game
.
drawVertical
(
0
,
0
,
1
);
// Left vertical line
game
.
drawHorizontal
(
0
,
1
,
1
);
// Bottom horizontal line
game
.
drawVertical
(
1
,
0
,
1
);
// Right vertical line
assertTrue
(
"Box should be completed"
,
game
.
boxComplete
(
0
,
0
));
}
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
testDrawHorizontalLineAlreadyDrawn
()
{
game
.
drawHorizontal
(
0
,
0
,
1
);
game
.
drawHorizontal
(
0
,
0
,
1
);
// Drawing the same line should throw an exception
}
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
testDrawVerticalLineAlreadyDrawn
()
{
game
.
drawVertical
(
0
,
0
,
1
);
game
.
drawVertical
(
0
,
0
,
1
);
// Drawing the same line should throw an exception
}
}
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