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
Ugochukwu Joseph Ekeh
Assessment 2
Compare revisions
95b234461c504af45b3085b6476f4ff230fd1229 to a9b1040e168fb3a7df6cc88f36d534324220c4c8
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
uekeh/assessment-2
Select target project
No results found
a9b1040e168fb3a7df6cc88f36d534324220c4c8
Select Git revision
Branches
1-bugfixing-assignment-error
main
Tags
testsfail
3 results
Swap
Target
uekeh/assessment-2
Select target project
uekeh/assessment-2
1 result
95b234461c504af45b3085b6476f4ff230fd1229
Select Git revision
Branches
1-bugfixing-assignment-error
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)
Unit test (@Test) initialisation
· 5e784972
Ugochukwu Joseph Ekeh
authored
1 year ago
5e784972
tried fixing bug
· a9b1040e
Ugochukwu Joseph Ekeh
authored
1 year ago
a9b1040e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+6
-6
6 additions, 6 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+29
-0
29 additions, 0 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
35 additions
and
6 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
View file @
a9b1040e
...
...
@@ -106,13 +106,13 @@ public class DotsAndBoxesGrid {
* @return true if all four sides have been drawn.
*/
public
boolean
boxComplete
(
int
x
,
int
y
)
{
if
(
x
>=
width
-
1
||
x
<
0
||
y
>=
height
-
1
||
y
<
0
)
{
return
fals
e
;
}
if
(
x
>=
width
+
1
||
x
<
0
||
y
>=
height
+
1
||
y
<
0
)
{
return
tru
e
;
}
else
{
// 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
tru
e
;
return
fals
e
;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
...
@@ -132,10 +132,10 @@ public class DotsAndBoxesGrid {
* @return true if it completes a box
*/
public
boolean
drawHorizontal
(
int
x
,
int
y
,
int
player
)
{
if
(
x
>=
width
-
1
||
x
<
0
)
{
if
(
x
>=
width
+
1
||
x
>
0
)
{
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"x was %d, which is out of range. Range is 0 to %d"
,
x
,
width
-
1
));
}
if
(
y
>=
height
||
y
<
0
)
{
if
(
y
>=
height
||
y
>
0
)
{
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
));
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
View file @
a9b1040e
...
...
@@ -27,5 +27,34 @@ public class DotsAndBoxesGridTest {
assertTrue
(
true
);
}
@Test
public
void
testBoxComplete
()
{
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
15
,
8
,
2
);
grid
.
drawVertical
(
1
,
4
,
0
);
grid
.
drawHorizontal
(
1
,
3
,
0
);
grid
.
drawHorizontal
(
2
,
3
,
0
);
boolean
completesBox
=
grid
.
drawVertical
(
2
,
4
,
0
);
assertEquals
(
true
,
completesBox
);
}
@Test
public
void
testBoxComplete
()
{
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
15
,
8
,
2
);
grid
.
drawVertical
(
1
,
4
,
0
);
grid
.
drawHorizontal
(
1
,
3
,
0
);
boolean
completesBox
=
grid
.
drawVertical
(
2
,
4
,
0
);
assertEquals
(
true
,
completesBox
);
}
@Test
public
void
testDrawHorizontal
()
{
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
15
,
8
,
2
);
grid
.
drawHorizontal
(
1
,
3
,
0
);
assertThrows
(
IndexOutOfBoundsException
.
class
,
()
->
{
grid
.
drawHorizontal
(
1
,
3
,
0
);
//"y was %d, which is out of range. Range is 0 to %d", y, height
});
}
// FIXME: You need to write tests for the two known bugs in the code.
}
This diff is collapsed.
Click to expand it.