Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hkaur28_Assignment2
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
hkaur28
hkaur28_Assignment2
Commits
d22a24aa
Commit
d22a24aa
authored
1 year ago
by
hkaur28
Browse files
Options
Downloads
Patches
Plain Diff
Bug fixed
parent
2dcf32c1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+11
-2
11 additions, 2 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+8
-4
8 additions, 4 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
19 additions
and
6 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+
11
−
2
View file @
d22a24aa
...
...
@@ -111,8 +111,12 @@ public class DotsAndBoxesGrid {
}
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
boolean
north
=
horizontals
[
x
][
y
];
boolean
south
=
horizontals
[
x
][
y
+
1
];
boolean
east
=
verticals
[
x
+
1
][
y
];
boolean
west
=
verticals
[
x
][
y
];
// FIXME: You'll need to fix this code (after writing a test first).
return
false
;
return
north
&&
south
&&
east
&&
west
;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
...
@@ -140,7 +144,9 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
if
(
horizontals
[
x
][
y
])
{
throw
new
IllegalArgumentException
(
"Already Drawn"
);
}
this
.
horizontals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
...
...
@@ -171,6 +177,9 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if
(
verticals
[
x
][
y
])
{
throw
new
IllegalArgumentException
(
"Already Drawn"
);
}
this
.
verticals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
...
...
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
8
−
4
View file @
d22a24aa
...
...
@@ -14,25 +14,29 @@ public class DotsAndBoxesGridTest {
@BeforeEach
public
void
setUp
()
{
// Create a new DotsAndBoxesGrid instance before each test
grid
=
new
DotsAndBoxesGrid
(
4
,
3
,
2
);
grid
=
new
DotsAndBoxesGrid
(
15
,
8
,
2
);
}
@Test
public
void
testBoxComplete
()
{
// Test if the boxComplete method works correctly
grid
.
drawHorizontal
(
3
,
3
,
1
);
grid
.
drawHorizontal
(
3
,
4
,
1
);
grid
.
drawVertical
(
3
,
3
,
1
);
grid
.
drawVertical
(
4
,
3
,
1
);
assertTrue
(
grid
.
boxComplete
(
3
,
3
));
}
@Test
public
void
whenExceptionThrown_thenAssertionSucceeds
()
{
Exception
exception
=
assertThrows
(
Exception
.
class
,
()
->
{
grid
.
drawHorizontal
(
3
,
3
,
1
);
Exception
exception
=
assertThrows
(
IllegalArgumentException
.
class
,
()
->
{
grid
.
drawHorizontal
(
3
,
3
,
1
);
});
String
expectedMessage
=
"Already Drawn"
;
String
actualMessage
=
exception
.
getMessage
();
System
.
out
.
println
(
actualMessage
);
assertTrue
(
actualMessage
.
contains
(
expectedMessage
));
}
...
...
This diff is collapsed.
Click to expand it.
hkaur28
@hkaur28
mentioned in issue
#2 (closed)
·
1 year ago
mentioned in issue
#2 (closed)
mentioned in issue #2
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