-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVerification.hpp
51 lines (44 loc) · 1.11 KB
/
Verification.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "ListNode.hpp"
class Verification {
public:
Verification() {}
bool verify(ListNode* userOutput, ListNode* referenceOutput, string& developer) {
ListNode* entry = userOutput;
ListNode* refEntry = referenceOutput;
bool success = true;
while (refEntry != nullptr) {
if (entry == nullptr || refEntry->val != entry->val) {
success = false;
break;
}
refEntry = refEntry->next;
entry = entry->next;
}
if (entry != nullptr) {
success = false;
}
refEntry = referenceOutput;
entry = userOutput;
if (not success) {
cout << "Expected output:" << endl << "[";
while (refEntry != nullptr) {
cout << refEntry->val;
refEntry = refEntry->next;
if (refEntry) {
cout << ",";
}
}
cout << "]" << endl;
cout << "Program output:" << endl << "[";
while (entry != nullptr) {
cout << entry->val;
entry = entry->next;
if (entry) {
cout << ",";
}
}
cout << "]" << endl;
}
return success;
}
};