-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverflow_calculator.cpp
46 lines (39 loc) · 2.02 KB
/
overflow_calculator.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
#include <iostream>
#define has_expired(time_stamp, current) ((int)((time_stamp) - (current)) >= 0)
struct timestamps
{
unsigned current;
unsigned start;
unsigned end;
};
void isInRange()
{
//Expected output is: 1 1 1 . 0 0 0 0 0
const int numOfTests = 10;
timestamps stamps[numOfTests] = {{4, 10239, 5}, {10239, 10238, 3}, {5, 1, 7}, {10, 10238, 3}, {10, 10239, 5}, {10, 1, 7}, {10, 11, 12}, {10, 10238, 3}, {10239, 10239, 5}, {5, 10238, 5}}; //last should fail!
for (int i = 0; i < numOfTests; i++)
{
bool isInRange= !((stamps[i].current - stamps[i].start) <= 0 && (stamps[i].current - stamps[i].end) >= 0);
bool isInRangeAlt = (!((stamps[i].current - stamps[i].start) <= 0) || !((stamps[i].current - stamps[i].end) >= 0));
bool isInRangeOld = (stamps[i].current >= stamps[i].start && stamps[i].current <= stamps[i].end);
bool isInRangeExp = (stamps[i].start > stamps[i].end) ? !(((int)(stamps[i].current - stamps[i].start) < 0) && ((int)(stamps[i].current - stamps[i].end) > 0)) : (stamps[i].current >= stamps[i].start && stamps[i].current <= stamps[i].end);
//bool isInRangeExp = (stamps[i].start > stamps[i].end) ? (!((int)(stamps[i].current - stamps[i].start)) > 0 || !((int)(stamps[i].current - stamps[i].end)) < 0) : (stamps[i].current >= stamps[i].start && stamps[i].current <= stamps[i].end);
bool isInRangeExp3 = !(stamps[i].current - stamps[i].start <= 0) && (stamps[i].current - stamps[i].end <=0);
bool isInRangeDlMacCe = !has_expired(stamps[i].start, stamps[i].current) && has_expired(stamps[i].end, stamps[i].current);
std::cout << " NEW:" << isInRange;
std::cout << " ALT: " << isInRangeAlt;
std::cout << " OLD: " << isInRangeOld;
//std::cout << " EXP2: " << isInRangeExp2;
std::cout << " EXP3: " << isInRangeExp3;
std::cout << " MACRO: " << isInRangeDlMacCe;
std::cout << " EXP: " << isInRangeExp << "\n";
}
}
// {4, 10239, 5} passes
// {10239, 10238, 3} passes
// {5, 1, 7} passes
int main()
{
isInRange();
return 0;
}