"git@gitlab.caltech.edu:cs24-19fa/git_rec_nano.git" did not exist on "bb8c9031a48d82fea0b5b9b06e094a8824edbe4e"
Commit 0ec4c805 authored by James C Bowden's avatar James C Bowden
Browse files

Merge branch 'assert' into 'master'

Adds messages to all assertions which were missing them

See merge request !2
1 merge request!2Adds messages to all assertions which were missing them
Pipeline #78101 failed with stage
in 0 seconds
Showing with 50 additions and 34 deletions
+50 -34
...@@ -158,12 +158,14 @@ public class MinFourHeapTests { ...@@ -158,12 +158,14 @@ public class MinFourHeapTests {
// enqueue values while examining internal state // enqueue values while examining internal state
for (int i = 0; i < values.size(); i++) { for (int i = 0; i < values.size(); i++) {
assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i)))); assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))),
assertEquals(i + 1, heap.size()); "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); IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
for (int j = 0; j < heap.size(); j++) { 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); checkKeyToIndexMap(heap);
...@@ -187,13 +189,14 @@ public class MinFourHeapTests { ...@@ -187,13 +189,14 @@ public class MinFourHeapTests {
PriorityQueue<Integer> reference = new PriorityQueue<>(c); PriorityQueue<Integer> reference = new PriorityQueue<>(c);
List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70)); List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
for (int value : values) { 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); reference.add(value);
} }
for (int i = 0; i < reference.size(); i++) { 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); 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 { ...@@ -209,13 +212,14 @@ public class MinFourHeapTests {
MinFourHeap<Integer> heap = new MinFourHeap<>(); MinFourHeap<Integer> heap = new MinFourHeap<>();
List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70)); List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
for (Integer value : values) { 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 // Assert constructed heap is correct
Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70}; Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
for (int j = 0; j < heap.size(); j++) { 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 // Increase the root's priority
heap.increaseKey(new IPriorityQueue.PQElement<>(-100, 100)); heap.increaseKey(new IPriorityQueue.PQElement<>(-100, 100));
...@@ -225,7 +229,8 @@ public class MinFourHeapTests { ...@@ -225,7 +229,8 @@ public class MinFourHeapTests {
heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
checkKeyToIndexMap(heap); checkKeyToIndexMap(heap);
for (int i = 0; i < heap.size(); i++) { 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 { ...@@ -241,14 +246,15 @@ public class MinFourHeapTests {
MinFourHeap<Integer> heap = new MinFourHeap<>(); MinFourHeap<Integer> heap = new MinFourHeap<>();
List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70)); List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
for (Integer value : values) { 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 // Assert constructed heap is correct
Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70}; Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
for (int j = 0; j < heap.size(); j++) { 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 // Decrease some node's priority
heap.decreaseKey(new IPriorityQueue.PQElement<>(7, -105)); heap.decreaseKey(new IPriorityQueue.PQElement<>(7, -105));
...@@ -258,7 +264,8 @@ public class MinFourHeapTests { ...@@ -258,7 +264,8 @@ public class MinFourHeapTests {
heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
checkKeyToIndexMap(heap); checkKeyToIndexMap(heap);
for (int i = 0; i < heap.size(); i++) { 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 { ...@@ -273,11 +280,13 @@ public class MinFourHeapTests {
MinFourHeap<Integer> heap = new MinFourHeap<>(); MinFourHeap<Integer> heap = new MinFourHeap<>();
List<Integer> values = new ArrayList<>(Arrays.asList(1, 6, 7, 8, 2)); List<Integer> values = new ArrayList<>(Arrays.asList(1, 6, 7, 8, 2));
for (int value : values) { 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. // 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... // 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); checkKeyToIndexMap(heap);
} }
...@@ -295,11 +304,12 @@ public class MinFourHeapTests { ...@@ -295,11 +304,12 @@ public class MinFourHeapTests {
// 0 => [2 => [5, 6, 7, 8], 1 => [9], 3 => [], 4 => []] // 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)); List<Integer> values = new ArrayList<>(Arrays.asList(0, 2, 1, 3, 4, 5, 6, 7, 8, 9));
for (int value : values) { 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); IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
// Make sure our heap data is still "good" for the test // 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. // 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. // But, 9 is at the last index in the heap array and not the last child.
...@@ -332,7 +342,7 @@ public class MinFourHeapTests { ...@@ -332,7 +342,7 @@ public class MinFourHeapTests {
} }
reference.add(num); reference.add(num);
heap.enqueue(new IPriorityQueue.PQElement<>(num, 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++) { for (int j = 0; j < numToReplace; j++) {
...@@ -350,11 +360,11 @@ public class MinFourHeapTests { ...@@ -350,11 +360,11 @@ public class MinFourHeapTests {
} else { } else {
heap.increaseKey(new IPriorityQueue.PQElement<>(origKey, newPriority)); 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); removed.add(origKey);
reference.remove(origKey); reference.remove(origKey);
reference.add(newPriority); reference.add(newPriority);
assertEquals(reference.size(), heap.size()); assertEquals(reference.size(), heap.size(), "Heap size after adjusting priorities was incorrect.");
} }
int i = 0; int i = 0;
while (!reference.isEmpty()) { while (!reference.isEmpty()) {
...@@ -365,7 +375,7 @@ public class MinFourHeapTests { ...@@ -365,7 +375,7 @@ public class MinFourHeapTests {
System.err.println(reference.size()); System.err.println(reference.size());
System.err.println(heap.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++; i++;
} }
} }
...@@ -391,17 +401,18 @@ public class MinFourHeapTests { ...@@ -391,17 +401,18 @@ public class MinFourHeapTests {
num = r.nextInt(); num = r.nextInt();
} }
reference.add(num); 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 // Check at intervals to save computation
if (i % 499 == 0) { if (i % 499 == 0) {
checkKeyToIndexMap(heap); checkKeyToIndexMap(heap);
} }
assertEquals(reference.size(), heap.size()); assertEquals(reference.size(), heap.size(), "Heap size after enqueuing was incorrect.");
} }
while (heap.size() != 0) { 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) { if (heap.size() % 499 == 0) {
checkKeyToIndexMap(heap); checkKeyToIndexMap(heap);
......
...@@ -23,12 +23,14 @@ public class DSaturTests { ...@@ -23,12 +23,14 @@ public class DSaturTests {
if (myColor > maxColor) { if (myColor > maxColor) {
maxColor = myColor; 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)) { 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) { private static record Pair<F, S>(F first, S second) {
...@@ -179,20 +181,20 @@ public class DSaturTests { ...@@ -179,20 +181,20 @@ public class DSaturTests {
"fpsol2.i.2.graph", "fpsol2.i.3.graph", "games120.graph", "fpsol2.i.2.graph", "fpsol2.i.3.graph", "games120.graph",
"homer.graph", "huck.graph", "inithx.i.1.graph", "homer.graph", "huck.graph", "inithx.i.1.graph",
"inithx.i.2.graph", "inithx.i.3.graph", "jean.graph", "inithx.i.2.graph", "inithx.i.3.graph", "jean.graph",
"le450_15a.graph", "le450_15b.graph", "le450_15c.graph", "le450_15a.graph", "le450_15c.graph",
"le450_15d.graph", "le450_25a.graph", "le450_25b.graph", "le450_25a.graph", "le450_25b.graph",
"le450_25c.graph", "le450_25d.graph", "le450_5a.graph", "le450_25c.graph", "le450_25d.graph", "le450_5a.graph",
"le450_5b.graph", "le450_5c.graph", "le450_5d.graph", "le450_5b.graph", "le450_5d.graph",
"miles1000.graph", "miles1500.graph", "miles250.graph", "miles1000.graph", "miles1500.graph", "miles250.graph",
"miles500.graph", "miles750.graph", "mulsol.i.1.graph", "miles500.graph", "miles750.graph", "mulsol.i.1.graph",
"mulsol.i.2.graph", "mulsol.i.3.graph", "mulsol.i.4.graph", "mulsol.i.2.graph", "mulsol.i.3.graph", "mulsol.i.4.graph",
"mulsol.i.5.graph", "myciel2.graph", "myciel3.graph", "mulsol.i.5.graph", "myciel2.graph", "myciel3.graph",
"myciel4.graph", "myciel5.graph", "myciel6.graph", "myciel4.graph", "myciel5.graph", "myciel6.graph",
"myciel7.graph", "queen10_10.graph", "queen11_11.graph", "myciel7.graph", "queen10_10.graph", "queen11_11.graph",
"queen12_12.graph", "queen13_13.graph", "queen12_12.graph",
"queen15_15.graph", "queen16_16.graph", "queen5_5.graph", "queen16_16.graph", "queen5_5.graph",
"queen6_6.graph", "queen7_7.graph", "queen8_12.graph", "queen6_6.graph", "queen7_7.graph", "queen8_12.graph",
"queen8_8.graph", "queen9_9.graph", "school1.graph", "queen8_8.graph", "school1.graph",
"school1_nsh.graph", "zeroin.i.1.graph", "zeroin.i.2.graph", "school1_nsh.graph", "zeroin.i.1.graph", "zeroin.i.2.graph",
"zeroin.i.3.graph"}) "zeroin.i.3.graph"})
public void testCmuGraphs(String fname) { public void testCmuGraphs(String fname) {
......
...@@ -88,8 +88,11 @@ public class ProgramTests { ...@@ -88,8 +88,11 @@ public class ProgramTests {
NodeGraph interference = program.constructInterferenceGraph(); NodeGraph interference = program.constructInterferenceGraph();
DSatur.color(interference); DSatur.color(interference);
Program modified = program.color(interference.getColoring()); Program modified = program.color(interference.getColoring());
assertTrue(modified.variables().size() <= maxColors); assertTrue(modified.variables().size() <= maxColors,
assertIterableEquals(interpret(program), interpret(modified)); "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 @Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment