forked from vikshanker/sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapping_integers_cmp.cc
38 lines (30 loc) · 931 Bytes
/
wrapping_integers_cmp.cc
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
#include "test_should_be.hh"
#include "util.hh"
#include "wrapping_integers.hh"
#include <cstdint>
#include <exception>
#include <iostream>
#include <optional>
#include <stdexcept>
#include <string>
using namespace std;
int main() {
try {
// Comparing low-number adjacent seqnos
test_should_be(WrappingInt32(3) != WrappingInt32(1), true);
test_should_be(WrappingInt32(3) == WrappingInt32(1), false);
size_t N_REPS = 4096;
auto rd = get_random_generator();
for (size_t i = 0; i < N_REPS; i++) {
uint32_t n = rd();
uint8_t diff = rd();
uint32_t m = n + diff;
test_should_be(WrappingInt32(n) == WrappingInt32(m), n == m);
test_should_be(WrappingInt32(n) != WrappingInt32(m), n != m);
}
} catch (const exception &e) {
cerr << e.what() << endl;
return 1;
}
return EXIT_SUCCESS;
}