Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Chantelle Perreau Assignment 2 COSC220
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
Chantelle Perreau
Chantelle Perreau Assignment 2 COSC220
Commits
a3fe99cc
Commit
a3fe99cc
authored
Jul 11, 2021
by
Chantelle Perreau
Browse files
Options
Downloads
Patches
Plain Diff
Tests added for known bugs
parent
d08d39b9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+52
-0
52 additions, 0 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
52 additions
and
0 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
52
−
0
View file @
a3fe99cc
...
@@ -7,6 +7,8 @@ import static org.junit.jupiter.api.Assumptions.*;
...
@@ -7,6 +7,8 @@ import static org.junit.jupiter.api.Assumptions.*;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
import
java.util.Random
;
public
class
DotsAndBoxesGridTest
{
public
class
DotsAndBoxesGridTest
{
/*
/*
* Because Test classes are classes, they can have fields, and can have static fields.
* Because Test classes are classes, they can have fields, and can have static fields.
...
@@ -28,4 +30,54 @@ public class DotsAndBoxesGridTest {
...
@@ -28,4 +30,54 @@ public class DotsAndBoxesGridTest {
}
}
// FIXME: You need to write tests for the two known bugs in the code.
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public
void
testBoxComplete
()
{
logger
.
info
(
"Test to show that game identifies when box is complete"
);
Random
rand
=
new
Random
();
int
width
=
rand
.
nextInt
(
100
)+
3
;
int
height
=
rand
.
nextInt
(
100
)+
3
;
DotsAndBoxesGrid
testGrid
=
new
DotsAndBoxesGrid
(
width
,
height
,
2
);
int
x
=
rand
.
nextInt
(
testGrid
.
width
-
1
);
int
y
=
rand
.
nextInt
(
testGrid
.
height
-
1
);
int
a
=
rand
.
nextInt
(
testGrid
.
width
-
1
);
int
b
=
rand
.
nextInt
(
testGrid
.
height
-
1
);
int
c
=
rand
.
nextInt
(
testGrid
.
width
-
1
);
int
d
=
rand
.
nextInt
(
testGrid
.
height
-
1
);
// A complete square which should assert to True
testGrid
.
drawHorizontal
(
x
,
y
,
1
);
testGrid
.
drawHorizontal
(
x
,
y
+
1
,
1
);
testGrid
.
drawVertical
(
x
,
y
,
1
);
testGrid
.
drawVertical
(
x
+
1
,
y
,
2
);
// An incomplete square which should assert to False
testGrid
.
drawHorizontal
(
a
,
b
,
2
);
testGrid
.
drawVertical
(
a
+
1
,
b
,
1
);
testGrid
.
drawVertical
(
a
,
b
,
1
);
assertTrue
(
testGrid
.
boxComplete
(
x
,
y
));
assertFalse
(
testGrid
.
boxComplete
(
a
,
b
));
// An unattempted square which should assert to False
assertFalse
(
testGrid
.
boxComplete
(
c
,
d
));
}
@Test
public
void
testLineAlreadyDrawn
()
{
logger
.
info
(
"Test to make sure exception is thrown when playing tries to draw an line that has already been drawn"
);
DotsAndBoxesGrid
testGrid
=
new
DotsAndBoxesGrid
(
15
,
8
,
2
);
Random
rand
=
new
Random
();
int
x
=
rand
.
nextInt
(
testGrid
.
width
-
1
);
int
y
=
rand
.
nextInt
(
testGrid
.
height
-
1
);
int
a
=
rand
.
nextInt
(
testGrid
.
width
-
1
);
int
b
=
rand
.
nextInt
(
testGrid
.
height
-
1
);
testGrid
.
drawHorizontal
(
x
,
y
,
1
);
testGrid
.
drawVertical
(
a
,
b
,
2
);
assertThrows
(
IllegalStateException
.
class
,
()
->
testGrid
.
drawHorizontal
(
x
,
y
,
1
),
"There "
+
"is already a line drawn here."
);
assertThrows
(
IllegalStateException
.
class
,
()
->
testGrid
.
drawHorizontal
(
x
,
y
,
2
),
"There "
+
"is already a line drawn here."
);
assertThrows
(
IllegalStateException
.
class
,
()
->
testGrid
.
drawVertical
(
a
,
b
,
1
),
"There "
+
"is already a line drawn here."
);
assertThrows
(
IllegalStateException
.
class
,
()
->
testGrid
.
drawVertical
(
a
,
b
,
2
),
"There "
+
"is already a line drawn here."
);
}
}
}
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