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-23wi
project06
Commits
5b251ca7
Commit
5b251ca7
authored
2 years ago
by
winterbloom
Browse files
Options
Download
Email Patches
Plain Diff
Adds messages to all assertions which were missing them
parent
ec5e6ead
master
1 merge request
!2
Adds messages to all assertions which were missing them
Pipeline
#78069
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
+34
-23
tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
tests/edu/caltech/cs2/project06/DSaturTests.java
+5
-3
tests/edu/caltech/cs2/project06/DSaturTests.java
tests/edu/caltech/cs2/project06/ProgramTests.java
+5
-2
tests/edu/caltech/cs2/project06/ProgramTests.java
with
44 additions
and
28 deletions
+44
-28
tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
View file @
5b251ca7
...
...
@@ -158,12 +158,14 @@ public class MinFourHeapTests {
// enqueue values while examining internal state
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
values
.
get
(
i
),
values
.
get
(
i
))));
assertEquals
(
i
+
1
,
heap
.
size
());
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
values
.
get
(
i
),
values
.
get
(
i
))),
"Enqueue unexpectedly returned false."
);
assertEquals
(
i
+
1
,
heap
.
size
(),
"Enqueue did not update size as appropriate."
);
IPriorityQueue
.
PQElement
<
Integer
>[]
heapData
=
Reflection
.
getFieldValue
(
MinFourHeap
.
class
,
"data"
,
heap
);
for
(
int
j
=
0
;
j
<
heap
.
size
();
j
++)
{
assertEquals
(
step_by_step
.
get
(
i
).
toArray
()[
j
],
heapData
[
j
].
data
);
assertEquals
(
step_by_step
.
get
(
i
).
toArray
()[
j
],
heapData
[
j
].
data
,
"Heap structure after enqueue is incorrect."
);
}
checkKeyToIndexMap
(
heap
);
...
...
@@ -187,13 +189,14 @@ public class MinFourHeapTests {
PriorityQueue
<
Integer
>
reference
=
new
PriorityQueue
<>(
c
);
List
<
Integer
>
values
=
new
ArrayList
<>(
Arrays
.
asList
(
9
,
-
100
,
19
,
3
,
-
2
,
1
,
7
,
-
84
,
-
4
,
2
,
70
));
for
(
int
value
:
values
)
{
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)));
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)),
"Enqueue unexpectedly returned false."
);
reference
.
add
(
value
);
}
for
(
int
i
=
0
;
i
<
reference
.
size
();
i
++)
{
assertEquals
(
reference
.
remove
(),
heap
.
dequeue
().
data
);
assertEquals
(
reference
.
remove
(),
heap
.
dequeue
().
data
,
"Dequeuing returned the incorrect value."
);
checkKeyToIndexMap
(
heap
);
assertEquals
(
reference
.
size
(),
heap
.
size
());
assertEquals
(
reference
.
size
(),
heap
.
size
()
,
"Dequeuing did not update size as appropriate."
);
}
}
...
...
@@ -209,13 +212,14 @@ public class MinFourHeapTests {
MinFourHeap
<
Integer
>
heap
=
new
MinFourHeap
<>();
List
<
Integer
>
values
=
new
ArrayList
<>(
Arrays
.
asList
(
9
,
-
100
,
19
,
3
,
-
2
,
1
,
7
,
-
84
,
-
4
,
2
,
70
));
for
(
Integer
value
:
values
)
{
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)));
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)),
"Enqueuing unexpectedly returned false."
);
}
// Assert constructed heap is correct
Integer
[]
correctHeapData
=
{-
100
,
-
84
,
2
,
3
,
-
2
,
9
,
7
,
1
,
-
4
,
19
,
70
};
IPriorityQueue
.
PQElement
<
Integer
>[]
heapData
=
Reflection
.
getFieldValue
(
MinFourHeap
.
class
,
"data"
,
heap
);
for
(
int
j
=
0
;
j
<
heap
.
size
();
j
++)
{
assertEquals
(
correctHeapData
[
j
],
heapData
[
j
].
data
);
assertEquals
(
correctHeapData
[
j
],
heapData
[
j
].
data
,
"Heap structure after enqueue is incorrect."
);
}
// Increase the root's priority
heap
.
increaseKey
(
new
IPriorityQueue
.
PQElement
<>(-
100
,
100
));
...
...
@@ -225,7 +229,8 @@ public class MinFourHeapTests {
heapData
=
Reflection
.
getFieldValue
(
MinFourHeap
.
class
,
"data"
,
heap
);
checkKeyToIndexMap
(
heap
);
for
(
int
i
=
0
;
i
<
heap
.
size
();
i
++)
{
assertEquals
(
correctHeapPrioritiesAfterIncrease
[
i
],
heapData
[
i
].
priority
);
assertEquals
(
correctHeapPrioritiesAfterIncrease
[
i
],
heapData
[
i
].
priority
,
"Priorities or layout after increaseKey is incorrect."
);
}
}
...
...
@@ -241,14 +246,15 @@ public class MinFourHeapTests {
MinFourHeap
<
Integer
>
heap
=
new
MinFourHeap
<>();
List
<
Integer
>
values
=
new
ArrayList
<>(
Arrays
.
asList
(
9
,
-
100
,
19
,
3
,
-
2
,
1
,
7
,
-
84
,
-
4
,
2
,
70
));
for
(
Integer
value
:
values
)
{
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)));
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)),
"Enqueuing unexpectedly returned false."
);
}
// Assert constructed heap is correct
Integer
[]
correctHeapData
=
{-
100
,
-
84
,
2
,
3
,
-
2
,
9
,
7
,
1
,
-
4
,
19
,
70
};
IPriorityQueue
.
PQElement
<
Integer
>[]
heapData
=
Reflection
.
getFieldValue
(
MinFourHeap
.
class
,
"data"
,
heap
);
for
(
int
j
=
0
;
j
<
heap
.
size
();
j
++)
{
assertEquals
(
correctHeapData
[
j
],
heapData
[
j
].
data
);
assertEquals
(
correctHeapData
[
j
],
heapData
[
j
].
data
,
"Heap structure after enqueue is incorrect."
);
}
// Decrease some node's priority
heap
.
decreaseKey
(
new
IPriorityQueue
.
PQElement
<>(
7
,
-
105
));
...
...
@@ -258,7 +264,8 @@ public class MinFourHeapTests {
heapData
=
Reflection
.
getFieldValue
(
MinFourHeap
.
class
,
"data"
,
heap
);
checkKeyToIndexMap
(
heap
);
for
(
int
i
=
0
;
i
<
heap
.
size
();
i
++)
{
assertEquals
(
correctHeapPrioritiesAfterDecrease
[
i
],
heapData
[
i
].
priority
);
assertEquals
(
correctHeapPrioritiesAfterDecrease
[
i
],
heapData
[
i
].
priority
,
"Priorities or layout after decreaseKey is incorrect."
);
}
}
...
...
@@ -273,11 +280,13 @@ public class MinFourHeapTests {
MinFourHeap
<
Integer
>
heap
=
new
MinFourHeap
<>();
List
<
Integer
>
values
=
new
ArrayList
<>(
Arrays
.
asList
(
1
,
6
,
7
,
8
,
2
));
for
(
int
value
:
values
)
{
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)));
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)),
"Enqueuing unexpectedly returned false."
);
}
// Dequeueing 1 won't cause any further percolations, since 2 is in the right place.
// There's some edge cases around this for some reason, which is why the test is here...
assertEquals
(
1
,
heap
.
dequeue
().
data
);
assertEquals
(
1
,
heap
.
dequeue
().
data
,
"Dequeuing unexpectedly rearranged the heap."
);
checkKeyToIndexMap
(
heap
);
}
...
...
@@ -295,11 +304,12 @@ public class MinFourHeapTests {
// 0 => [2 => [5, 6, 7, 8], 1 => [9], 3 => [], 4 => []]
List
<
Integer
>
values
=
new
ArrayList
<>(
Arrays
.
asList
(
0
,
2
,
1
,
3
,
4
,
5
,
6
,
7
,
8
,
9
));
for
(
int
value
:
values
)
{
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)));
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
value
,
value
)),
"Enqueuing unexpectedly returned false."
);
}
IPriorityQueue
.
PQElement
<
Integer
>[]
heapData
=
Reflection
.
getFieldValue
(
MinFourHeap
.
class
,
"data"
,
heap
);
// Make sure our heap data is still "good" for the test
assertEquals
(
10
,
heapData
.
length
,
"Heap data array is not a default size of 10 or was resized prematurely"
);
assertEquals
(
10
,
heapData
.
length
,
"Heap data array is not a default size of 10 or was resized prematurely
.
"
);
// Increase the node at the root. The node gets swapped with 1, then compared against children.
// But, 9 is at the last index in the heap array and not the last child.
...
...
@@ -332,7 +342,7 @@ public class MinFourHeapTests {
}
reference
.
add
(
num
);
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
num
,
num
));
assertEquals
(
reference
.
size
(),
heap
.
size
());
assertEquals
(
reference
.
size
(),
heap
.
size
()
,
"Heap size after enqueue was incorrect."
);
}
for
(
int
j
=
0
;
j
<
numToReplace
;
j
++)
{
...
...
@@ -350,11 +360,11 @@ public class MinFourHeapTests {
}
else
{
heap
.
increaseKey
(
new
IPriorityQueue
.
PQElement
<>(
origKey
,
newPriority
));
}
assertEquals
(
reference
.
size
(),
heap
.
size
());
assertEquals
(
reference
.
size
(),
heap
.
size
()
,
"Heap size after adjusting priorities was incorrect."
);
removed
.
add
(
origKey
);
reference
.
remove
(
origKey
);
reference
.
add
(
newPriority
);
assertEquals
(
reference
.
size
(),
heap
.
size
());
assertEquals
(
reference
.
size
(),
heap
.
size
()
,
"Heap size after adjusting priorities was incorrect."
);
}
int
i
=
0
;
while
(!
reference
.
isEmpty
())
{
...
...
@@ -365,7 +375,7 @@ public class MinFourHeapTests {
System
.
err
.
println
(
reference
.
size
());
System
.
err
.
println
(
heap
.
size
());
}
assertEquals
((
double
)
er
,
mr
.
priority
);
assertEquals
((
double
)
er
,
mr
.
priority
,
"Priorities after adjusting them and dequeuing were incorrect."
);
i
++;
}
}
...
...
@@ -391,17 +401,18 @@ public class MinFourHeapTests {
num
=
r
.
nextInt
();
}
reference
.
add
(
num
);
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
num
,
num
)));
assertTrue
(
heap
.
enqueue
(
new
IPriorityQueue
.
PQElement
<>(
num
,
num
)),
"Enqueuing unexpectedly returned false."
);
// Check at intervals to save computation
if
(
i
%
499
==
0
)
{
checkKeyToIndexMap
(
heap
);
}
assertEquals
(
reference
.
size
(),
heap
.
size
());
assertEquals
(
reference
.
size
(),
heap
.
size
()
,
"Heap size after enqueuing was incorrect."
);
}
while
(
heap
.
size
()
!=
0
)
{
assertEquals
(
reference
.
remove
(),
heap
.
dequeue
().
data
);
assertEquals
(
reference
.
remove
(),
heap
.
dequeue
().
data
,
"Dequeuing returned the wrong element."
);
if
(
heap
.
size
()
%
499
==
0
)
{
checkKeyToIndexMap
(
heap
);
...
...
This diff is collapsed.
Click to expand it.
tests/edu/caltech/cs2/project06/DSaturTests.java
View file @
5b251ca7
...
...
@@ -23,12 +23,14 @@ public class DSaturTests {
if
(
myColor
>
maxColor
)
{
maxColor
=
myColor
;
}
assertTrue
(
myColor
>
0
);
assertTrue
(
myColor
>
0
,
"All of the vertices in the graph must be colored when you're done."
);
for
(
int
neighbor
:
g
.
neighbors
(
i
))
{
assertTrue
(
myColor
!=
g
.
getColor
(
neighbor
));
assertTrue
(
myColor
!=
g
.
getColor
(
neighbor
),
"Invalid coloring: two adjacent vertices share the same color."
);
}
}
assertTrue
(
maxColor
<=
N
,
""
+
maxColor
+
" is supposed to be <= "
+
N
);
assertTrue
(
maxColor
<=
N
,
maxColor
+
" is supposed to be <= "
+
N
);
}
private
static
record
Pair
<
F
,
S
>(
F
first
,
S
second
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/edu/caltech/cs2/project06/ProgramTests.java
View file @
5b251ca7
...
...
@@ -88,8 +88,11 @@ public class ProgramTests {
NodeGraph
interference
=
program
.
constructInterferenceGraph
();
DSatur
.
color
(
interference
);
Program
modified
=
program
.
color
(
interference
.
getColoring
());
assertTrue
(
modified
.
variables
().
size
()
<=
maxColors
);
assertIterableEquals
(
interpret
(
program
),
interpret
(
modified
));
assertTrue
(
modified
.
variables
().
size
()
<=
maxColors
,
"Interference graph coloring uses more colors than expected "
+
"(ie: more variables were connected by edges than expected)."
);
assertIterableEquals
(
interpret
(
program
),
interpret
(
modified
),
"Interference graph does not validly "
+
" reflect interferences (ie: the resulting program overwrites its own variables)."
);
}
@Test
...
...
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