-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
68 lines (53 loc) · 1.41 KB
/
test.c
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
#include <math.h>
#include <stdio.h>
#include "mapper_expr.h"
int test1()
{
const char str[] = "y=26*2/2+log10(pi)+2.*pow(2,1*(3+7*.1)*1.1+x{-6*2+12})*3*4+cos(2.)";
mapper_expr e = mapper_expr_new_from_string(str, 1, 1, 1);
printf("Parsing %s\n", str);
if (!e) { printf("Test FAILED.\n"); return 1; }
#ifdef DEBUG
printexpr("Parser returned: ", e);
#endif
printf("\n");
float inp, outp;
inp = 3.0;
mapper_expr_evaluate(e, &inp, &outp);
printf("Evaluate with x=%f: %f (expected: %f)\n",
inp, outp,
26*2/2+log10f(M_PI)+2.f*powf(2,1*(3+7*.1f)*1.1f+inp)*3*4+cosf(2.0f));
mapper_expr_free(e);
return 0;
}
int test2()
{
const char str[] = "y=26*2/2+x*30/(20*1)";
mapper_expr e = mapper_expr_new_from_string(str, 0, 0, 1);
printf("\nParsing %s\n", str);
if (!e) { printf("Test FAILED.\n"); return 1; }
#ifdef DEBUG
printexpr("Parser returned: ", e);
#endif
printf("\n");
int inp, outp;
inp = 3;
mapper_expr_evaluate(e, &inp, &outp);
printf("Evaluate with x=%d: %d (expected: %d)\n",
inp, outp,
26*2/2+inp*30/(20*1));
inp = 321;
mapper_expr_evaluate(e, &inp, &outp);
printf("Evaluate with x=%d: %d (expected: %d)\n",
inp, outp,
26*2/2+inp*30/(20*1));
mapper_expr_free(e);
return 0;
}
int main()
{
int rc=0;
rc|=test1();
rc|=test2();
return rc;
}