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
c9adaeb6
Commit
c9adaeb6
authored
4 years ago
by
Archie Shahidullah
Browse files
Options
Download
Email Patches
Plain Diff
Update LinkedDequeTests.java
parent
95ab28ab
1 merge request
!1
Review Tests for Project 3
Pipeline
#36409
canceled with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/edu/caltech/cs2/datastructures/LinkedDequeTests.java
+84
-1
tests/edu/caltech/cs2/datastructures/LinkedDequeTests.java
with
84 additions
and
1 deletion
+84
-1
tests/edu/caltech/cs2/datastructures/LinkedDequeTests.java
View file @
c9adaeb6
package
edu.caltech.cs2.datastructures
;
import
edu.caltech.cs2.helpers.Inspection
;
import
edu.caltech.cs2.helpers.NodeChecker
;
import
edu.caltech.cs2.helpers.Reflection
;
import
edu.caltech.cs2.helpers.RuntimeInstrumentation
;
import
edu.caltech.cs2.interfaces.ICollection
;
...
...
@@ -12,14 +13,18 @@ import org.junit.jupiter.api.*;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
import
org.junit.jupiter.params.provider.ValueSource
;
import
org.junit.platform.engine.support.hierarchical.Node
;
import
java.lang.reflect.Constructor
;
import
java.sql.Ref
;
import
java.util.*
;
import
java.util.ArrayDeque
;
import
java.util.function.Consumer
;
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
.
assertNull
;
@Tag
(
"C"
)
@TestMethodOrder
(
MethodOrderer
.
OrderAnnotation
.
class
)
...
...
@@ -80,6 +85,13 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
Reflection
.
assertNoPublicFields
(
LinkedDeque
.
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
...
...
@@ -109,6 +121,19 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
Inspection
.
assertConstructorHygiene
(
LINKED_DEQUE_SOURCE
);
}
@Order
(
classSpecificTestLevel
)
@DisplayName
(
"Check for linked node class"
)
@Test
public
void
testLinkedNode
()
{
Class
[]
classes
=
LinkedDeque
.
class
.
getDeclaredClasses
();
for
(
Class
clazz
:
classes
)
{
if
(
Iterator
.
class
.
isAssignableFrom
(
clazz
))
{
continue
;
}
NodeChecker
.
isNode
(
clazz
,
true
);
}
}
// TOSTRING TESTS ---------------------------------------------------
...
...
@@ -257,4 +282,62 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
RuntimeInstrumentation
.
assertAtMost
(
"peekBack"
,
RuntimeInstrumentation
.
ComplexityType
.
CONSTANT
,
provide
,
peekBack
,
8
);
}
}
\ No newline at end of file
@Order
(
dequeTestLevel
)
@DisplayName
(
"Cycle detection for addFront(...) and addBack(...)"
)
@ParameterizedTest
(
name
=
"Test cycles {1} random numbers with seed = {0}"
)
@CsvSource
({
"69, 200"
,
"20, 300"
})
public
void
checkForCycles
(
int
seed
,
int
size
)
{
Random
r
=
new
Random
(
seed
);
Deque
<
Object
>
reference
=
new
ArrayDeque
<>();
IDeque
<
Object
>
impl
=
new
LinkedDeque
<>();
// Test that first peek is null
assertNull
(
impl
.
peekFront
(),
"empty peek should return null"
);
// Test adding values updates size and displays contained correctly
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
num
=
r
.
nextInt
();
if
(
num
%
2
==
0
)
{
reference
.
addLast
(
num
);
impl
.
addBack
(
num
);
}
else
{
reference
.
addFirst
(
num
);
impl
.
addFront
(
num
);
}
NodeChecker
.
cycleDetection
(
impl
,
true
);
assertEquals
(
reference
.
size
(),
impl
.
size
(),
"size()s are not equal"
);
assertEquals
(
reference
.
toString
(),
impl
.
toString
(),
"toStrings()s are not equal"
);
}
}
@Order
(
dequeTestLevel
)
@DisplayName
(
"Check reverses for addFront(...) and addBack(...)"
)
@ParameterizedTest
(
name
=
"Test reverse {1} random numbers with seed = {0}"
)
@CsvSource
({
"31, 200"
,
"64, 300"
})
public
void
checkReverses
(
int
seed
,
int
size
)
{
Random
r
=
new
Random
(
seed
);
Deque
<
Object
>
reference
=
new
ArrayDeque
<>();
IDeque
<
Object
>
impl
=
new
LinkedDeque
<>();
// Test that first peek is null
assertNull
(
impl
.
peekFront
(),
"empty peek should return null"
);
// Test adding values updates size and displays contained correctly
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
num
=
r
.
nextInt
();
if
(
num
%
2
==
0
)
{
reference
.
addLast
(
num
);
impl
.
addBack
(
num
);
}
else
{
reference
.
addFirst
(
num
);
impl
.
addFront
(
num
);
}
NodeChecker
.
checkReverse
(
impl
);
assertEquals
(
reference
.
size
(),
impl
.
size
(),
"size()s are not equal"
);
assertEquals
(
reference
.
toString
(),
impl
.
toString
(),
"toStrings()s are not equal"
);
}
}
}
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