-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathto_bool.cpp
47 lines (44 loc) · 1.48 KB
/
to_bool.cpp
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
#include "emp-tool/emp-tool.h"
#include <iostream>
using namespace std;
using namespace emp;
struct testMe {
uint64_t x;
uint64_t y;
uint32_t z;
uint8_t t;
};
// Just testing to see if we can move some arbitrary arrays of structs to bool and back again.
int main() {
uint8_t len = 100;
struct testMe structs[len];
struct testMe output[len];
bool b[len * 8 * sizeof(struct testMe)];
for (uint64_t i = 0; i < len; ++i) {
structs[i].x = i << 50;
structs[i].y = (i + 1) << 50;
structs[i].z = ((uint32_t) i) << 20;
structs[i].t = (uint8_t) i;
}
to_bool(b, structs, len * 8 * sizeof(struct testMe));
from_bool(b, output, len * 8 * sizeof(struct testMe));
for (uint64_t i = 0; i < len; ++i) {
if (output[i].x != i << 50) {
std::cerr << "in to_bool, output[" << i << "].x was " << output[i].x << " when it should be " << (i << 50) << "\n";
return -1;
}
if (output[i].y != (i + 1) << 50) {
std::cerr << "in to_bool, output[" << i << "].y was " << output[i].y << " when it should be " << ((i + 1) << 50) << "\n";
return -1;
}
if (output[i].z != ((uint32_t) i) << 20) {
std::cerr << "in to_bool, output[" << i << "].z was " << output[i].z << " when it should be " << (((uint32_t) i) << 20) << "\n";
return -1;
}
if (output[i].t != (uint8_t) i) {
std::cerr << "in to_bool, output[" << i << "].t was " << output[i].t << " when it should be " << ((uint8_t) i) << "\n";
return -1;
}
}
return 0;
}