Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs2-20wi
project03
Commits
f8d205c8
Commit
f8d205c8
authored
4 years ago
by
Archie Shahidullah
Browse files
Options
Download
Email Patches
Plain Diff
Update CircularArrayFixedSizeQueueTests.java
parent
86eab90b
1 merge request
!1
Review Tests for Project 3
Pipeline
#36407
canceled with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/edu/caltech/cs2/datastructures/CircularArrayFixedSizeQueueTests.java
+49
-1
.../cs2/datastructures/CircularArrayFixedSizeQueueTests.java
with
49 additions
and
1 deletion
+49
-1
tests/edu/caltech/cs2/datastructures/CircularArrayFixedSizeQueueTests.java
View file @
f8d205c8
...
...
@@ -17,6 +17,7 @@ import java.util.function.Function;
import
static
edu
.
caltech
.
cs2
.
project03
.
Project03TestOrdering
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
fail
;
@Tag
(
"B"
)
@TestMethodOrder
(
MethodOrderer
.
OrderAnnotation
.
class
)
...
...
@@ -70,6 +71,13 @@ public class CircularArrayFixedSizeQueueTests implements FixedSizeQueueTests {
Reflection
.
assertNoPublicFields
(
CircularArrayFixedSizeQueue
.
class
);
}
@Order
(
classSpecificTestLevel
)
@DisplayName
(
"There are no protected fields"
)
@Test
public
void
testNoProtectedFields
()
{
Reflection
.
assertNoProtectedFields
(
LinkedDeque
.
class
);
}
@Order
(
classSpecificTestLevel
)
@DisplayName
(
"The public interface is correct"
)
@Test
...
...
@@ -158,4 +166,44 @@ public class CircularArrayFixedSizeQueueTests implements FixedSizeQueueTests {
RuntimeInstrumentation
.
assertAtMost
(
"peek"
,
RuntimeInstrumentation
.
ComplexityType
.
CONSTANT
,
provide
,
peek
,
8
);
}
}
\ No newline at end of file
@Order
(
fixedSizeQueueLevel
)
@DisplayName
(
"Test iterator matches reference"
)
@ParameterizedTest
(
name
=
"Test iterator with {1} random values with seed = {0} and fixed array size = {2}"
)
@CsvSource
({
"69, 200, 20"
,
"21, 300, 200"
})
public
void
testWrapAround
(
int
seed
,
int
numVals
,
int
queueSize
)
{
Random
r
=
new
Random
(
seed
);
Constructor
c
=
Reflection
.
getConstructor
(
CircularArrayFixedSizeQueue
.
class
,
int
.
class
);
IFixedSizeQueue
<
Object
>
me
=
newFixedSizeQueue
(
queueSize
);
Queue
<
Object
>
reference
=
new
java
.
util
.
ArrayDeque
<>();
assertEquals
(
queueSize
,
me
.
capacity
(),
"capacity does not match expected value"
);
for
(
int
i
=
0
;
i
<
queueSize
;
i
++)
{
int
num
=
r
.
nextInt
();
assertEquals
(
false
,
me
.
isFull
(),
"queue should not be full"
);
assertEquals
(
true
,
me
.
enqueue
(
num
),
"enqueue should be successful"
);
reference
.
add
(
num
);
}
for
(
int
i
=
0
;
i
<
numVals
;
i
++)
{
me
.
enqueue
(
me
.
dequeue
());
reference
.
add
(
reference
.
remove
());
assertEquals
(
reference
.
peek
(),
me
.
peek
(),
"return values of peek()s are not equal"
);
assertEquals
(
reference
.
size
(),
me
.
size
(),
"size()s are not equal"
);
assertEquals
(
queueSize
,
me
.
capacity
(),
"capacity does not match expected value"
);
Iterator
<
Object
>
meItr
=
me
.
iterator
();
Iterator
<
Object
>
refItr
=
reference
.
iterator
();
while
(
meItr
.
hasNext
())
{
if
(!
refItr
.
hasNext
())
{
fail
(
"Implemented queue has more values than reference queue"
);
}
assertEquals
(
refItr
.
next
(),
meItr
.
next
(),
"next()s are not equal"
);
}
if
(
refItr
.
hasNext
())
{
fail
(
"Reference queue has more values than implemented queue"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help