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
2860e23a
Commit
2860e23a
authored
4 years ago
by
Ethan Ordentlich
Browse files
Options
Download
Email Patches
Plain Diff
Fix #4
Add test for array initial capacity
parent
290faf92
1 merge request
!2
Small revisions
Pipeline
#43060
canceled with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
+36
-2
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
tests/edu/caltech/cs2/project03/Project03TestOrdering.java
+7
-3
tests/edu/caltech/cs2/project03/Project03TestOrdering.java
with
43 additions
and
5 deletions
+43
-5
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
View file @
2860e23a
...
...
@@ -17,7 +17,7 @@ import java.util.stream.Stream;
import
static
edu
.
caltech
.
cs2
.
project03
.
Project03TestOrdering
.*;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
SECONDS
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
*
;
@TestMethodOrder
(
MethodOrderer
.
OrderAnnotation
.
class
)
@Tag
(
"C"
)
...
...
@@ -126,6 +126,40 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
Inspection
.
assertConstructorHygiene
(
ARRAY_DEQUE_SOURCE
);
}
// ARRAYDEQUE TESTS ---------------------------------------------------
@Order
(
implSpecificTestLevel
)
@Test
public
void
testArrayDequeDefaultInitialCapacity
()
throws
IllegalAccessException
{
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
// Reflect and get the backing array
Field
arr
=
Reflection
.
getFieldByType
(
ArrayDeque
.
class
,
int
[].
class
);
arr
.
setAccessible
(
true
);
int
[]
backingArray
=
(
int
[])
arr
.
get
(
impl
);
assertEquals
(
10
,
backingArray
.
length
,
"Default initial capacity is not 10"
);
}
@Order
(
implSpecificTestLevel
)
@DisplayName
(
"enqueue should always succeed"
)
@Test
public
void
testThatArrayDequeEnqueueAlwaysSucceeds
()
{
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
assertTrue
(
impl
.
enqueue
(
i
),
"enqueue should always succeed for ArrayDeque"
);
}
}
@Order
(
implSpecificTestLevel
)
@DisplayName
(
"push should always succeed"
)
@Test
public
void
testThatArrayDequePushAlwaysSucceeds
()
{
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
assertTrue
(
impl
.
push
(
i
),
"push should always succeed for ArrayDeque"
);
}
}
// TOSTRING TESTS ---------------------------------------------------
...
...
@@ -174,7 +208,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
}
@Order
(
complexityTestLevel
)
@DisplayName
(
"addBack() and removeBack() take
linear
time"
)
@DisplayName
(
"addBack() and removeBack() take
constant
time"
)
@Timeout
(
value
=
20
,
unit
=
SECONDS
)
@Test
public
void
testBackDequeOperationComplexity
()
{
...
...
This diff is collapsed.
Click to expand it.
tests/edu/caltech/cs2/project03/Project03TestOrdering.java
View file @
2860e23a
...
...
@@ -5,6 +5,7 @@ public final class Project03TestOrdering {
throw
new
InstantiationError
(
"Class is only for storing constant variables"
);
}
// Tests related to class structure
public
static
final
int
classSpecificTestLevel
=
0
;
public
static
final
int
collectionTestLevel
=
1
;
...
...
@@ -14,8 +15,11 @@ public final class Project03TestOrdering {
public
static
final
int
fixedSizeQueueLevel
=
3
;
public
static
final
int
toStringTestLevel
=
4
;
public
static
final
int
co
mpl
exity
TestLevel
=
5
;
// Tests related to the particular implementation
public
static
final
int
i
mpl
Specific
TestLevel
=
4
;
public
static
final
int
guitarStringTestLevel
=
6
;
public
static
final
int
toStringTestLevel
=
5
;
public
static
final
int
complexityTestLevel
=
6
;
public
static
final
int
guitarStringTestLevel
=
7
;
}
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