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
d92faa87
Commit
d92faa87
authored
4 years ago
by
Archie Shahidullah
Browse files
Options
Download
Email Patches
Plain Diff
timeout tests and other fixes
parent
656caae1
1 merge request
!1
Review Tests for Project 3
Pipeline
#36467
canceled with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
+36
-14
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
tests/edu/caltech/cs2/datastructures/CircularArrayFixedSizeQueueTests.java
+6
-4
.../cs2/datastructures/CircularArrayFixedSizeQueueTests.java
tests/edu/caltech/cs2/datastructures/LinkedDequeTests.java
+12
-4
tests/edu/caltech/cs2/datastructures/LinkedDequeTests.java
with
54 additions
and
22 deletions
+54
-22
tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java
View file @
d92faa87
...
...
@@ -15,17 +15,19 @@ import org.junit.jupiter.params.provider.ValueSource;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Field
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Consumer
;
import
java.util.function.Function
;
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
;
@TestMethodOrder
(
MethodOrderer
.
OrderAnnotation
.
class
)
@Tag
(
"C"
)
public
class
ArrayDequeTests
implements
DequeTests
,
StackTests
,
QueueTests
{
private
static
String
ARRAY_DEQUE_SOURCE
=
"src/edu/caltech/cs2/datastructures/ArrayDeque.java"
;
private
static
String
ARRAY_DEQUE_SOURCE
=
"src/edu/caltech/cs2/datastructures/ArrayDeque.java"
;
private
Constructor
arrayDequeConstructor
=
Reflection
.
getConstructor
(
ArrayDeque
.
class
);
...
...
@@ -42,7 +44,7 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
}
public
IQueue
<
Object
>
newQueue
()
{
return
Reflection
.
newInstance
(
arrayDequeConstructor
);
return
Reflection
.
newInstance
(
arrayDequeConstructor
);
}
public
IQueue
<
Object
>
newQueue
(
int
size
)
{
...
...
@@ -104,8 +106,22 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
@DisplayName
(
"The public interface is correct"
)
@Test
public
void
testPublicInterface
()
{
Reflection
.
assertPublicInterface
(
ArrayDeque
.
class
,
List
.
of
(
"addFront"
,
"addBack"
,
"removeFront"
,
"removeBack"
,
"enqueue"
,
"dequeue"
,
"push"
,
"pop"
,
"peek"
,
"peekFront"
,
"peekBack"
,
"iterator"
,
"size"
,
"toString"
));
Reflection
.
assertPublicInterface
(
ArrayDeque
.
class
,
List
.
of
(
"addFront"
,
"addBack"
,
"removeFront"
,
"removeBack"
,
"enqueue"
,
"dequeue"
,
"push"
,
"pop"
,
"peek"
,
"peekFront"
,
"peekBack"
,
"iterator"
,
"size"
,
"toString"
));
}
@Order
(
classSpecificTestLevel
)
...
...
@@ -115,6 +131,7 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
Inspection
.
assertConstructorHygiene
(
ARRAY_DEQUE_SOURCE
);
}
// TOSTRING TESTS ---------------------------------------------------
@Order
(
toStringTestLevel
)
...
...
@@ -127,7 +144,9 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
toStringTestLevel
)
@DisplayName
(
"toString() matches java.util.ArrayDeque"
)
@ParameterizedTest
(
name
=
"Test toString() on [{arguments}]"
)
@ValueSource
(
strings
=
{
"0, 1, 2, 3"
,
"5, 4, 3, 2, 1"
,
"8, 3, 5, 7, 4, 3, 12, 12, 1"
})
@ValueSource
(
strings
=
{
"0, 1, 2, 3"
,
"5, 4, 3, 2, 1"
,
"8, 3, 5, 7, 4, 3, 12, 12, 1"
})
public
void
testToString
(
String
inputs
)
{
java
.
util
.
ArrayDeque
<
String
>
reference
=
new
java
.
util
.
ArrayDeque
<
String
>();
edu
.
caltech
.
cs2
.
datastructures
.
ArrayDeque
<
String
>
me
=
new
edu
.
caltech
.
cs2
.
datastructures
.
ArrayDeque
<>();
...
...
@@ -142,6 +161,7 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"addFront() and removeFront() take linear time"
)
@Timeout
(
value
=
20
,
unit
=
SECONDS
)
@Test
()
public
void
testFrontDequeOperationComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -155,12 +175,12 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
Consumer
<
IDeque
<
Integer
>>
removeFront
=
(
IDeque
<
Integer
>
q
)
->
q
.
removeFront
();
RuntimeInstrumentation
.
assertAtMost
(
"addFront"
,
RuntimeInstrumentation
.
ComplexityType
.
LINEAR
,
provide
,
addFront
,
8
);
RuntimeInstrumentation
.
assertAtMost
(
"removeFront"
,
RuntimeInstrumentation
.
ComplexityType
.
LINEAR
,
provide
,
removeFront
,
8
);
RuntimeInstrumentation
.
assertAtMost
(
"removeFront"
,
RuntimeInstrumentation
.
ComplexityType
.
LINEAR
,
provide
,
removeFront
,
8
);
}
@Order
(
complexityTestLevel
)
@DisplayName
(
"addBack() and removeBack() take linear time"
)
@Timeout
(
value
=
20
,
unit
=
SECONDS
)
@Test
public
void
testBackDequeOperationComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -174,12 +194,12 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
Consumer
<
IDeque
<
Integer
>>
removeBack
=
(
IDeque
<
Integer
>
q
)
->
q
.
removeBack
();
RuntimeInstrumentation
.
assertAtMost
(
"addBack"
,
RuntimeInstrumentation
.
ComplexityType
.
LINEAR
,
provide
,
addBack
,
8
);
RuntimeInstrumentation
.
assertAtMost
(
"removeBack"
,
RuntimeInstrumentation
.
ComplexityType
.
LINEAR
,
provide
,
removeBack
,
8
);
RuntimeInstrumentation
.
assertAtMost
(
"removeBack"
,
RuntimeInstrumentation
.
ComplexityType
.
LINEAR
,
provide
,
removeBack
,
8
);
}
@Order
(
complexityTestLevel
)
@DisplayName
(
"enqueue() and dequeue() take linear time"
)
@Timeout
(
value
=
20
,
unit
=
SECONDS
)
@Test
public
void
testQueueOperationComplexity
()
{
Function
<
Integer
,
IQueue
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -198,6 +218,7 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"push() and pop() take constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testStackOperationComplexity
()
{
Function
<
Integer
,
IStack
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -216,6 +237,7 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"peek() takes constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testPeekComplexity
()
{
Function
<
Integer
,
IStack
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -232,6 +254,7 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"peekFront() takes constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
()
public
void
testPeekFrontComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -243,12 +266,12 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
};
Consumer
<
IDeque
<
Integer
>>
peekFront
=
(
IDeque
<
Integer
>
q
)
->
q
.
peekFront
();
RuntimeInstrumentation
.
assertAtMost
(
"peekFront"
,
RuntimeInstrumentation
.
ComplexityType
.
CONSTANT
,
provide
,
peekFront
,
8
);
RuntimeInstrumentation
.
assertAtMost
(
"peekFront"
,
RuntimeInstrumentation
.
ComplexityType
.
CONSTANT
,
provide
,
peekFront
,
8
);
}
@Order
(
complexityTestLevel
)
@DisplayName
(
"peekBack() takes constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testPeekBackComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -260,8 +283,7 @@ public class ArrayDequeTests implements DequeTests, StackTests, QueueTests {
};
Consumer
<
IDeque
<
Integer
>>
peekBack
=
(
IDeque
<
Integer
>
q
)
->
q
.
peekBack
();
RuntimeInstrumentation
.
assertAtMost
(
"peekBack"
,
RuntimeInstrumentation
.
ComplexityType
.
CONSTANT
,
provide
,
peekBack
,
8
);
RuntimeInstrumentation
.
assertAtMost
(
"peekBack"
,
RuntimeInstrumentation
.
ComplexityType
.
CONSTANT
,
provide
,
peekBack
,
8
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/edu/caltech/cs2/datastructures/CircularArrayFixedSizeQueueTests.java
View file @
d92faa87
...
...
@@ -5,7 +5,6 @@ import edu.caltech.cs2.helpers.Reflection;
import
edu.caltech.cs2.helpers.RuntimeInstrumentation
;
import
edu.caltech.cs2.interfaces.IFixedSizeQueue
;
import
edu.caltech.cs2.interfaces.IQueue
;
import
org.hamcrest.collection.IsIterableContainingInOrder
;
import
org.junit.jupiter.api.*
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
...
...
@@ -17,6 +16,7 @@ import java.util.function.Consumer;
import
java.util.function.Function
;
import
static
edu
.
caltech
.
cs2
.
project03
.
Project03TestOrdering
.*;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
SECONDS
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@Tag
(
"B"
)
...
...
@@ -129,6 +129,7 @@ public class CircularArrayFixedSizeQueueTests implements FixedSizeQueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"enqueue() and dequeue() take constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
()
public
void
testQueueOperationComplexity
()
{
Function
<
Integer
,
IFixedSizeQueue
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -148,6 +149,7 @@ public class CircularArrayFixedSizeQueueTests implements FixedSizeQueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"peek() takes constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
()
public
void
testPeekComplexity
()
{
Function
<
Integer
,
IFixedSizeQueue
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -164,8 +166,8 @@ public class CircularArrayFixedSizeQueueTests implements FixedSizeQueueTests {
}
@Order
(
fixedSizeQueueLevel
)
@DisplayName
(
"Test iterator matches reference"
)
@ParameterizedTest
(
name
=
"Test iterator with {1} random values with seed = {0} and fixed array size = {2}"
)
@DisplayName
(
"Test iterator matches reference
for wraparound values
"
)
@ParameterizedTest
(
name
=
"Test iterator
and wraparound behavior
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
);
...
...
@@ -188,5 +190,5 @@ public class CircularArrayFixedSizeQueueTests implements FixedSizeQueueTests {
assertIterableEquals
(
reference
,
me
,
"Reference and implemented queues are not equal"
);
}
}
}
This diff is collapsed.
Click to expand it.
tests/edu/caltech/cs2/datastructures/LinkedDequeTests.java
View file @
d92faa87
...
...
@@ -21,6 +21,7 @@ import java.util.function.Consumer;
import
java.util.function.Function
;
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
.
assertNull
;
...
...
@@ -152,6 +153,7 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"addFront() and removeFront() take constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testFrontDequeOperationComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -172,6 +174,7 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"addBack() and removeBack() take constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testBackDequeOperationComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -191,6 +194,7 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"enqueue() and dequeue() take constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testQueueOperationComplexity
()
{
Function
<
Integer
,
IQueue
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -209,6 +213,7 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"push() and pop() take constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testStackOperationComplexity
()
{
Function
<
Integer
,
IStack
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -227,6 +232,7 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"peek() takes constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testPeekComplexity
()
{
Function
<
Integer
,
IStack
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -243,6 +249,7 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"peekFront() takes constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testPeekFrontComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -260,6 +267,7 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
@Order
(
complexityTestLevel
)
@DisplayName
(
"peekBack() takes constant time"
)
@Timeout
(
value
=
10
,
unit
=
SECONDS
)
@Test
public
void
testPeekBackComplexity
()
{
Function
<
Integer
,
IDeque
<
Integer
>>
provide
=
(
Integer
numElements
)
->
{
...
...
@@ -276,8 +284,8 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
}
@Order
(
dequeTestLevel
)
@DisplayName
(
"Cycle detection for addFront(...) a
nd add
Back(...)"
)
@ParameterizedTest
(
name
=
"Test cycles {1} random numbers with seed = {0}"
)
@DisplayName
(
"Cycle detection for addFront(...)
,
a
ddBack(...), removeFront(...), and remove
Back(...)"
)
@ParameterizedTest
(
name
=
"Test cycles
-
{1} random numbers with seed = {0}"
)
@CsvSource
({
"69, 2000"
,
"20, 3000"
})
public
void
checkForCycles
(
int
seed
,
int
size
)
{
Random
r
=
new
Random
(
seed
);
...
...
@@ -311,8 +319,8 @@ public class LinkedDequeTests implements DequeTests, StackTests, QueueTests {
}
@Order
(
dequeTestLevel
)
@DisplayName
(
"Check reverses for addFront(...) a
nd add
Back(...)"
)
@ParameterizedTest
(
name
=
"Test reverse {1} random numbers with seed = {0}"
)
@DisplayName
(
"Check reverses for addFront(...)
,
a
ddBack(...), removeFront(...), and remove
Back(...)"
)
@ParameterizedTest
(
name
=
"Test reverse
-
{1} random numbers with seed = {0}"
)
@CsvSource
({
"31, 2000"
,
"64, 3000"
})
public
void
checkReverses
(
int
seed
,
int
size
)
{
Random
r
=
new
Random
(
seed
);
...
...
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