Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
assessment-2
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
Jack Scarfe
assessment-2
Commits
6c251d5f
Commit
6c251d5f
authored
2 years ago
by
Jack Scarfe
Browse files
Options
Downloads
Patches
Plain Diff
Added Unit Tests that detect the errors in the code
parent
3ead5ba0
No related branches found
Branches containing commit
Tags
testsfail
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+44
-6
44 additions, 6 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
44 additions
and
6 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
44
−
6
View file @
6c251d5f
...
...
@@ -19,13 +19,51 @@ public class DotsAndBoxesGridTest {
* The typical format of a test is that it contains some code that does something, and then one
* or more assertions to check that a condition holds.
*
* This is a dummy test just to show that the test suite itself runs
*/
// Unit test to determine if the boxComplete algorithm correctly discerns a box is complete
// This test is currently vacuously true - it's not failing but that isn't indicative of
// the algorithm working - the function simply always returns true for values of x and y where
// 0 < x < width-1 OR 0 < y < height-1
@Test
public
void
testTestSuiteRuns
()
{
logger
.
info
(
"Dummy test to show the test suite runs"
);
assertTrue
(
true
);
}
public
void
testBoxIsComplete
()
{
// test against box that is known to be complete
DotsAndBoxesGrid
test1
=
new
DotsAndBoxesGrid
(
4
,
4
,
2
);
test1
.
drawHorizontal
(
0
,
0
,
0
);
test1
.
drawVertical
(
0
,
0
,
1
);
test1
.
drawHorizontal
(
0
,
1
,
0
);
test1
.
drawVertical
(
1
,
0
,
1
);
assertTrue
(
test1
.
boxComplete
(
0
,
0
));
}
// Unit test to determine if the boxComplete correctly discerns a box is not complete
@Test
public
void
testBoxIsNotComplete
()
{
// test against 'box' that is known to not be complete
DotsAndBoxesGrid
test2
=
new
DotsAndBoxesGrid
(
6
,
6
,
2
);
test2
.
drawHorizontal
(
0
,
0
,
0
);
test2
.
drawVertical
(
0
,
0
,
1
);
test2
.
drawHorizontal
(
2
,
0
,
0
);
test2
.
drawVertical
(
2
,
0
,
1
);
assertFalse
(
test2
.
boxComplete
(
0
,
0
));
}
// FIXME: You need to write tests for the two known bugs in the code.
// Unit test to determine if the horizontal draw function permits you to draw over a line that has already been drawn
@Test
public
void
testHorizontalLineAlreadyDrawn
()
{
DotsAndBoxesGrid
test
=
new
DotsAndBoxesGrid
(
5
,
5
,
2
);
test
.
drawHorizontal
(
1
,
0
,
0
);
assertThrows
(
IllegalStateException
.
class
,
()
->
{
test
.
drawHorizontal
(
1
,
0
,
0
);
});
}
// Unit test to determine if the vertical draw function permits you to draw over a line that has already been drawn
@Test
public
void
testVerticalLineAlreadyDrawn
()
{
DotsAndBoxesGrid
test
=
new
DotsAndBoxesGrid
(
5
,
5
,
2
);
test
.
drawVertical
(
1
,
0
,
0
);
assertThrows
(
IllegalStateException
.
class
,
()
->
{
test
.
drawVertical
(
1
,
0
,
0
);
});
}
}
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