Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Assessment2-Software-development-task-Juan_Ludevid
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
Juan Ludevid
Assessment2-Software-development-task-Juan_Ludevid
Commits
378c7bf3
Commit
378c7bf3
authored
2 years ago
by
Juan Ludevid
Browse files
Options
Downloads
Patches
Plain Diff
bugs have been fixed
parent
c23f7667
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Issue has been fixed through commit 378c7bf3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+8
-3
8 additions, 3 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+5
-6
5 additions, 6 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
13 additions
and
9 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+
8
−
3
View file @
378c7bf3
...
...
@@ -112,7 +112,8 @@ 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
(
this
.
horizontals
[
x
][
y
]
&&
this
.
horizontals
[
x
][
y
+
1
]
&&
this
.
verticals
[
x
][
y
]
&&
this
.
verticals
[
x
+
1
][
y
]);
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
...
@@ -140,7 +141,9 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
if
(
this
.
horizontals
[
x
][
y
])
{
throw
new
IllegalStateException
(
String
.
format
(
"horizontal line at [%d][%d] has been drawn already"
,
x
,
y
));
}
this
.
horizontals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
...
...
@@ -171,7 +174,9 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if
(
this
.
verticals
[
x
][
y
])
{
throw
new
IllegalStateException
(
String
.
format
(
"Vertical line at [%d][%d] has been drawn already"
,
x
,
y
));
}
this
.
verticals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
boolean
claimE
=
claimBox
(
x
,
y
,
player
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
5
−
6
View file @
378c7bf3
...
...
@@ -45,19 +45,18 @@ public class DotsAndBoxesGridTest {
case2
.
drawHorizontal
(
0
,
0
,
0
);
case2
.
drawVertical
(
0
,
0
,
1
);
case2
.
drawHorizontal
(
0
,
1
,
0
);
case2
.
drawVertical
(
0
,
0
,
1
);
assertFalse
(
case2
.
boxComplete
(
0
,
0
));
}
@Test
public
void
drawMethodsDetectRedrawnLines
()
{
// code to test that drawHorizontal throws an exception if the line was already drawn goes here
DotsAndBoxesGrid
case3
=
new
DotsAndBoxesGrid
(
5
,
5
,
2
);
case3
.
drawHorizontal
(
0
,
0
,
1
);
case3
.
drawVertical
(
0
,
0
,
1
);
assertAll
(
()->
assertThrows
(
IllegalStateException
.
class
,
()->
case3
.
drawHorizontal
(
0
,
0
,
1
),
"No horizonal line has been drawn"
),
()->
assertThrows
(
IllegalStateException
.
class
,
()->
case3
.
drawVertical
(
0
,
0
,
1
),
"No vertical line has been drawn"
)
);
case3
.
drawHorizontal
(
0
,
0
,
1
);
assertAll
(
()->
assertThrows
(
IllegalStateException
.
class
,
()->
case3
.
drawVertical
(
0
,
0
,
1
),
"No vertical line has been drawn"
),
()->
assertThrows
(
IllegalStateException
.
class
,
()->
case3
.
drawHorizontal
(
0
,
0
,
1
),
"No horizonal line has been drawn"
)
);
}
...
...
This diff is collapsed.
Click to expand it.
Juan Ludevid
@jludevid
mentioned in commit
7e8aca82
·
2 years ago
mentioned in commit
7e8aca82
mentioned in commit 7e8aca8239fda1618d8620847956abe1fc83bdb9
Toggle commit list
Juan Ludevid
@jludevid
mentioned in issue
#1 (closed)
·
2 years ago
mentioned in issue
#1 (closed)
mentioned in issue #1
Toggle commit list
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