Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
A2
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
Matt Ralston
A2
Compare revisions
5da13ec9565ea15a463470c16a5972fa26991c44 to b24e4aa47b22a4d0494f7a11076fbfac89ec4997
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
mralston/a2
Select target project
No results found
b24e4aa47b22a4d0494f7a11076fbfac89ec4997
Select Git revision
Branches
1-two-known-bugs
main
Tags
testsfail
3 results
Swap
Target
mralston/a2
Select target project
mralston/a2
1 result
5da13ec9565ea15a463470c16a5972fa26991c44
Select Git revision
Branches
1-two-known-bugs
main
Tags
testsfail
3 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source
2
Added unit tests
· 3a48c12e
Matt Ralston
authored
Jul 4, 2023
3a48c12e
Fixed two known bugs
· b24e4aa4
Matt Ralston
authored
Jul 4, 2023
b24e4aa4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+4
-3
4 additions, 3 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+30
-1
30 additions, 1 deletion
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
34 additions
and
4 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
View file @
b24e4aa4
...
...
@@ -111,8 +111,7 @@ public class DotsAndBoxesGrid {
}
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
// FIXME: You'll need to fix this code (after writing a test first).
return
true
;
return
horizontals
[
x
][
y
]
&&
horizontals
[
x
][
y
+
1
]
&&
verticals
[
x
][
y
]
&&
verticals
[
x
+
1
][
y
];
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
...
@@ -139,7 +138,9 @@ public class DotsAndBoxesGrid {
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
));
}
// FIXME: You need to throw an exception if the line was already drawn.
if
(
this
.
horizontals
[
x
][
y
])
{
throw
new
IllegalStateException
(
String
.
format
(
"line at %d, %d was already drawn and cannot be redrawn."
,
x
,
y
));
}
this
.
horizontals
[
x
][
y
]
=
true
;
...
...
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
View file @
b24e4aa4
...
...
@@ -27,5 +27,34 @@ public class DotsAndBoxesGridTest {
assertTrue
(
true
);
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public
void
boxCompleteDetectsCompletedBoxes
()
{
logger
.
info
(
"Test to show that boxComplete returns true if all sides have been drawn"
);
DotsAndBoxesGrid
case1
=
new
DotsAndBoxesGrid
(
4
,
4
,
1
);
case1
.
drawHorizontal
(
0
,
0
,
0
);
case1
.
drawVertical
(
0
,
0
,
1
);
case1
.
drawHorizontal
(
0
,
1
,
0
);
case1
.
drawVertical
(
1
,
0
,
1
);
assertTrue
(
case1
.
boxComplete
(
0
,
0
));
}
@Test
public
void
boxCompleteDetectsIncompleteBoxes
()
{
logger
.
info
(
"Test to show that boxComplete returns false if not all sides have been drawn"
);
DotsAndBoxesGrid
case1
=
new
DotsAndBoxesGrid
(
4
,
4
,
1
);
case1
.
drawHorizontal
(
0
,
0
,
0
);
case1
.
drawVertical
(
0
,
0
,
1
);
case1
.
drawHorizontal
(
0
,
1
,
0
);
assertFalse
(
case1
.
boxComplete
(
0
,
0
));
}
@Test
public
void
drawMethodsDetectRedrawnLines
()
{
logger
.
info
(
"Test to show that drawHorizontal throws an exception if the line was already drawn"
);
DotsAndBoxesGrid
case1
=
new
DotsAndBoxesGrid
(
4
,
4
,
1
);
case1
.
drawHorizontal
(
0
,
0
,
0
);
assertThrows
(
IllegalStateException
.
class
,
()
->
{
case1
.
drawHorizontal
(
0
,
0
,
0
);
});
}
}
This diff is collapsed.
Click to expand it.