-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.cpp
More file actions
35 lines (29 loc) · 874 Bytes
/
validate.cpp
File metadata and controls
35 lines (29 loc) · 874 Bytes
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
#include "solution.hpp"
#include <fstream>
#include <iostream>
#include <stdexcept>
uint32_t original_solution(const char *file_name) {
std::fstream file_stream{file_name};
if (not file_stream.is_open())
throw std::runtime_error{"The file could not be opened"};
uint32_t crc = 0xff'ff'ff'ffu;
char c;
while (true) {
file_stream.read(&c, 1);
if (file_stream.eof())
break;
update_crc32(crc, static_cast<uint8_t>(c));
}
return crc ^ 0xff'ff'ff'ffu;
}
int main() {
const auto original_result = original_solution(small_data);
const auto result = solution(small_data);
if (original_result != result) {
std::cerr << "Validation Failed. Original result = " << original_result
<< "; Modified version returned = " << result << "\n";
return 1;
}
std::cout << "Validation Successful" << std::endl;
return 0;
}