-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_test_calc_reduce.h
71 lines (56 loc) · 2.19 KB
/
test_test_calc_reduce.h
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
/* test_test_calc_reduce.c */
typedef struct {
int ok;
int not_ok;
} result;
bool test(char *filename);
static void fail(const char *msg);
static bool diff_check(const char *var, const double act, const double exp, const double prec);
static bool diff_check_int(const char *var, const int act, const int exp);
static bool diff_check_degree(const char *var, const double act, const double exp, const double prec);
static bool diff_check_char(const char *var, const char *act, const char *exp);
static bool calcsAsExpected(
const double juldate,
const int planet,
const int flags,
const int flags_exp,
const double expectedResult[],
const double precision[],
const char *expectedMessage );
static void computePrecisions( double precisions[6], int precisionsExp[6] );
static result executeTestSet(FILE* testdata);
static int hasMoreTestSets(FILE* testdata, testHeader* header);
static double arcdiff(double x, double y);
// Precision for checks on floating numbers
static double defaultPrecision = 1.0e-7;
const double DEG2ARC = 0.017453292519943295769236907684886;
const double deg360 = .36e3;
const double deg180 = .18e3;
static inline double arcdiff( double x, double y ) {
double d = (x-y)/deg360+.5;
return (d-floor(d))*deg360-deg180;
}
static inline void fail(const char* msg) {
fprintf(stderr,msg);
exit(EXIT_FAILURE);
}
static inline bool diff_check( const char* var, const double act, const double exp, const double prec) {
bool ok = fabs(act - exp ) < prec;
if (!ok) printf("\n%15s : %15.10f <> %15.10f",var,act,exp);
return ok;
}
static inline bool diff_check_int( const char* var, const int act, const int exp) {
bool ok = (act == exp);
if (!ok) printf("\n%15s : %d <> %d",var,act,exp);
return ok;
}
static inline bool diff_check_degree( const char* var, const double act, const double exp, const double prec) {
bool ok = fabs(arcdiff(act,exp) ) < prec;
if (!ok) printf("\n%15s : %15.10f <> %15.10f",var,act,exp);
return ok;
}
static inline bool diff_check_char( const char *var, const char* act, const char* exp) {
bool ok = ! strcmp(act,exp);
if (!ok) printf("\n%15s : '%s' <> '%s'",var,act,exp);
return ok;
}