-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
56 lines (55 loc) · 1.42 KB
/
test.cpp
File metadata and controls
56 lines (55 loc) · 1.42 KB
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
52
53
54
55
56
#include <iostream>
#include "Hamming84.h"
using namespace std;
// Return false if errors where not detected and wrong result returned
bool test(int errors = 0) {
Hamming84::ParamStore<uint8_t> buffer;
bool correctOrDetected = true;
for(int i = 0;i <= 255; ++i) {
// Encode
uint8_t in = i;
Hamming84::encode(in, buffer);
uint8_t out = 0;
if (errors) {
int pos = i;
int e = errors;
do {
int error = 0x01 << (pos % 8);
buffer[pos % 2] ^= error;
pos += 3;
} while(e--);
}
// Introduce a bit error
if(!Hamming84::decode(out, buffer)) {
cout << i << ": decodeHelper failed" << endl;
continue;
}
if(out != in) {
cout << i << ": wrong result" << endl;
correctOrDetected = false;
}
}
return correctOrDetected;
}
int main() {
cout << "Testing w/o bit error" << endl;
if(!test()) {
return 1;
}
cout << "Testing w single bit error" << endl;
if(!test(1)) {
return 1;
}
cout << "Testing w double bit error" << endl;
if(!test(2)) {
return 1;
}
cout << "Double Bit Errors Detected but not corrected" << endl;
cout << "Testing w triple bit error" << endl;
if(!test(3)) {
return 1;
}
cout << "Triple Bit Errors Detected but not corrected" << endl;
cout << "Everything works as expected" << endl;
return 0;
}