-
Notifications
You must be signed in to change notification settings - Fork 21
/
fixedtest.cpp
60 lines (45 loc) · 1.12 KB
/
fixedtest.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
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <random>
#include <fixed.hpp>
#include <unit.hpp>
using namespace sweet;
UNITTEST(decimal1) {
Fixed d(1);
std::cout<<std::fixed<<d<<std::endl;
}
UNITTEST(decimal2) {
Fixed d("1.5");
d*=4;
d*=4.0;
d-=4;
d-=4.0;
d/=4;
d/=4.0;
d+=4;
d+=4.0;
std::cout<<std::fixed<<d<<std::endl;
}
UNITTEST(randomGen) {
std::random_device rd;
std::mt19937 m(rd());
std::uniform_real_distribution<> dist(
std::numeric_limits<int32_t>::min()/2,
std::numeric_limits<int32_t>::max()/2
);
/*for(size_t i = 0; i < std::numeric_limits<size_t>::max() / 100000; ++i) {
double a(dist(m));
double b(dist(m));
AS_EQ(Fixed(std::to_string(a)) + Fixed(std::to_string(b)),
Fixed(std::to_string(a+b)));
AS_EQ(Fixed(std::to_string(a)) - Fixed(std::to_string(b)),
Fixed(std::to_string(a-b)));
AS_EQ(Fixed(std::to_string(a)) * Fixed(std::to_string(b)),
Fixed(std::to_string(a*b)));
AS_EQ(Fixed(std::to_string(a)) / Fixed(std::to_string(b)),
Fixed(std::to_string(a/b)));
AS_EQ(Fixed(std::to_string(a)) < Fixed(std::to_string(b)),
a < b);
AS_EQ(Fixed(std::to_string(a)) > Fixed(std::to_string(b)),
a > b);
}
*/
}