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
730392cc
Commit
730392cc
authored
4 years ago
by
Ethan Ordentlich
Browse files
Options
Download
Email Patches
Plain Diff
Fix test for array capacity
parent
2860e23a
1 merge request
!2
Small revisions
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
+8
-4
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
with
8 additions
and
4 deletions
+8
-4
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
View file @
730392cc
...
@@ -129,14 +129,18 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
...
@@ -129,14 +129,18 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
// ARRAYDEQUE TESTS ---------------------------------------------------
// ARRAYDEQUE TESTS ---------------------------------------------------
@Order
(
implSpecificTestLevel
)
@Order
(
implSpecificTestLevel
)
@DisplayName
(
"The default capacity of the array is 10"
)
@Test
@Test
public
void
testArrayDequeDefaultInitialCapacity
()
throws
IllegalAccessException
{
public
void
testArrayDequeDefaultInitialCapacity
()
throws
IllegalAccessException
{
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
// Reflect and get the backing array
// Reflect and get the backing array
Field
arr
=
Reflection
.
getFieldByType
(
ArrayDeque
.
class
,
int
[].
class
);
// It's actually an Object[] since that's how it (should!) be initialized internally
// Casting it doesn't change the type of the field.
// It's fine since there should only be one array.
Field
arr
=
Reflection
.
getFieldByType
(
ArrayDeque
.
class
,
Object
[].
class
);
arr
.
setAccessible
(
true
);
arr
.
setAccessible
(
true
);
i
nt
[]
backingArray
=
(
i
nt
[])
arr
.
get
(
impl
);
I
nt
eger
[]
backingArray
=
(
I
nt
eger
[])
arr
.
get
(
impl
);
assertEquals
(
10
,
backingArray
.
length
,
"Default initial capacity is not 10"
);
assertEquals
(
10
,
backingArray
.
length
,
"Default initial capacity is not 10"
);
}
}
...
@@ -147,7 +151,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
...
@@ -147,7 +151,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
public
void
testThatArrayDequeEnqueueAlwaysSucceeds
()
{
public
void
testThatArrayDequeEnqueueAlwaysSucceeds
()
{
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
assertTrue
(
impl
.
enqueue
(
i
),
"enqueue should always succeed for ArrayDeque"
);
assertTrue
(
impl
.
enqueue
(
i
),
"enqueue
()
should always succeed for ArrayDeque"
);
}
}
}
}
...
@@ -157,7 +161,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
...
@@ -157,7 +161,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
public
void
testThatArrayDequePushAlwaysSucceeds
()
{
public
void
testThatArrayDequePushAlwaysSucceeds
()
{
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
ArrayDeque
<
Integer
>
impl
=
new
ArrayDeque
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
assertTrue
(
impl
.
push
(
i
),
"push should always succeed for ArrayDeque"
);
assertTrue
(
impl
.
push
(
i
),
"push
()
should always succeed for ArrayDeque"
);
}
}
}
}
...
...
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