PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/expr_test.c

http://ftk.googlecode.com/
C | 69 lines | 63 code | 6 blank | 0 comment | 2 complexity | db642bbede050850a09bb644077a51ba MD5 | raw file
 1#include "ftk.h"
 2#include "ftk_expr.h"
 3
 4typedef struct tagTESTCASE_T
 5{
 6	double val;
 7	char* expr;
 8}TESTCASE_T, *PTESTCASE_T;
 9
10TESTCASE_T g_aTestcase[] =
11{
12	{0.5, "0.5"},
13	{8, "010"},
14	{9, "011"},
15	{1, "0x1"},
16	{1, "0x001"},
17	{15, "0x0F"},
18	{15, "0XF"},
19	{5, "05"},
20	{15, "05+(5+0x5)"},
21	{1, "1.00"},
22	{3, "1.5+1.5"},
23	{3, "1+1+1"},
24	{3, "(1+1+1)*1.00"},
25	{7.5, "(1.2+1.8)*2.5"},
26	{1, "1"},
27	{2, "1+1"},
28	{1, "1|1"},
29	{3, "2|1"},
30	{1, "1&1"},
31	{0, "2&1"},
32	{3, "1+1+1"},
33	{4, "(1+1)*2"},
34	{5, "2*2+1"},
35	{6, "2+(2*2)"},
36	{7, "(1+2)+(2*2)"},
37	{8, "64/8)"},
38	{9, "(82-1)/9)"},
39	{0, "(64/8-8)"},
40	{1, "  1  "},
41	{2, "  1  +  1  "},
42	{3, "  1  +  1  +  1"},
43	{4, "  (  1  +  1  )  *  2  "},
44	{5, "  2  *  2  +  1  "},
45	{6, "  2  +  (  2  *  2  )"},
46	{7, "  (  1  +  2  )  +  (  2  *  2  )  "},
47	{8, "  64 /  8  ) "},
48	{9, "  (  82 -  1  )  /  9  )  "},
49	{0, "  (  64 /  8  -  8  )  "},
50	{0, NULL}
51};
52
53int main(int argc, char* argv[])
54{
55	int i = 0;
56	double val = 0;
57
58	ftk_set_allocator(ftk_allocator_default_create());
59	while(g_aTestcase[i].expr != NULL)
60	{
61		val = ftk_expr_eval(g_aTestcase[i].expr);
62		printf("%s=%lf\n", g_aTestcase[i].expr, val);
63		assert(g_aTestcase[i].val == val);
64
65		i++;
66	}
67	
68	return 0;
69}