-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGo.cpp
More file actions
109 lines (81 loc) · 2.12 KB
/
testGo.cpp
File metadata and controls
109 lines (81 loc) · 2.12 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
extern "C" int get4Roots(struct Z [][4], const double *, int);
#include "roots.h"
#include <random>
#include <complex>
#include <gtest/gtest.h>
#define EPS 1E-8
//TEST(GTest, DISABLED_4thRootTiny)
TEST(GTest, 4thRootTiny)
{
const int N = 100;
double a[N];
const double UP = 1e-2;
double lower_bound = -(UP/2);
double upper_bound = -lower_bound;
std::uniform_real_distribution<double> unif(lower_bound,upper_bound);
std::default_random_engine re;
for (int i=0; i<N; i++)
{
a[i] = unif(re);
}
struct Z root[N][4];
get4Roots(root, a, N);
for(int i = 0; i < N; i++)
{
for(int j = 0; j < 4; j++)
{
std::complex<double> z(root[i][j].Re, root[i][j].Im);
double delta = std::abs((std::pow(z, 4) - a[i])) / a[i];
EXPECT_NEAR(delta, 0, EPS);
}
}
}
TEST(GTest, 4thRootSmall)
{
const int N = 100;
double a[N];
const int UP = 1e5;
int lower_bound = -(UP>>1);
int upper_bound = -lower_bound;
std::uniform_real_distribution<double> unif(lower_bound,upper_bound);
std::default_random_engine re;
for (int i=0; i<N; i++)
{
a[i] = unif(re);
}
struct Z root[N][4];
get4Roots(root, a, N);
for(int i = 0; i < N; i++)
{
for(int j = 0; j < 4; j++)
{
std::complex<double> z(root[i][j].Re, root[i][j].Im);
double delta = std::abs((std::pow(z, 4) - a[i])) / a[i];
EXPECT_NEAR(delta, 0, EPS);
}
}
}
TEST(GTest, 4thRootHuge)
{
const int N = 100;
double a[N];
int64_t lower_bound = -(UINT64_MAX>>1);
int64_t upper_bound = -lower_bound;
std::uniform_real_distribution<double> unif(lower_bound,upper_bound);
std::default_random_engine re;
for (int i=0; i<N; i++)
{
a[i] = unif(re);
}
struct Z root[N][4];
get4Roots(root, a, N);
for(int i = 0; i < N; i++)
{
for(int j = 0; j < 4; j++)
{
std::complex<double> z(root[i][j].Re, root[i][j].Im);
double delta = std::abs((std::pow(z, 4) - a[i])) / a[i];
EXPECT_NEAR(delta, 0, EPS);
}
}
}