void test_assignment(void) { printf("\ntest_assignment\n"); { struct Node* f0 = node_new(__ASSIGNMENT); struct Node* n0 = create_declarator_scalar(); struct Complex* n1val = complex_new(111,222); struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)n1val); node_link(f0, n0); node_link(f0, n1); calcnode(f0); } { struct Node* f0 = node_new(__ASSIGNMENT); struct Node* n0 = create_declarator_array(); struct Complex* n1val = complex_new(333,444); struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)n1val); node_link(f0, n0); node_link(f0, n1); calcnode(f0); } g(); }
void f(void) { const char* m0name = "aiueo"; mem_create_var(m0name, MTT_COMPVAL, 100); struct MemTag* m0 = mem_read_var_memtag(m0name, 0); m0->address = (void*)complex_new(123, 456); printf("f(), &m0:[%p] ", m0); struct Complex* cn0vp = (struct Complex*)m0->address; printf("m0->address[%f, %f]\n", complex_realpart(*cn0vp), complex_imagpart(*cn0vp)); const char* m1name = "kakikukeko"; mem_create_var(m1name, MTT_COMPVAL, 100); struct MemTag* m1 = mem_read_var_memtag(m1name, 0); m1->address = (void*)complex_new(1234, 5678); printf("f(), &m1:[%p] ", m1); struct Complex* cn1vp = (struct Complex*)m1->address; printf("m1->address[%f, %f]\n", complex_realpart(*cn1vp), complex_imagpart(*cn1vp)); }
struct Node* create_selection_if(void) { struct Node* f0 = node_new(__SELECTION_IF); struct Complex* n0val = complex_new(1, 0); struct Node* n0 = node_new_leaf(__CONST_FLOAT, (void*)n0val); struct Complex* n1val = complex_new(2, 0); struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)n1val); struct Complex* n2val = complex_new(3, 0); struct Node* n2 = node_new_leaf(__CONST_FLOAT, (void*)n2val); node_link(f0, n0); node_link(f0, n1); node_link(f0, n2); return f0; }
void test_complex() { complexFloat c = complex_new(1,2); CU_ASSERT(c.real==1); CU_ASSERT(c.imag==2); complexFloat d = complex_add(c,complex_zero()); CU_ASSERT(d.real==1); CU_ASSERT(d.imag==2); d = complex_sub(c,complex_new(-1,-2)); CU_ASSERT(d.real==2); CU_ASSERT(d.imag==4); CU_ASSERT(within_tol(complex_amp(c),sqrt(5))); CU_ASSERT(within_tol(complex_amp(d),sqrt(20))); CU_ASSERT(within_tol(complex_amp_sqr(c),5)); CU_ASSERT(within_tol(complex_amp_sqr(d),20)); CU_ASSERT(within_tol(complex_amp(complex_scale(d,.5)),sqrt(5))); d = complex_conj(c); CU_ASSERT(d.real==1); CU_ASSERT(d.imag==-2); complexFloat e = complex_conj(complex_add(d,complex_conj(c))); CU_ASSERT(e.real==2); CU_ASSERT(e.imag==4); complexVector v = complex_vector_new(c,d,e); CU_ASSERT(v.A.real==1); CU_ASSERT(v.A.imag==2); CU_ASSERT(v.B.real==1); CU_ASSERT(v.B.imag==-2); CU_ASSERT(v.C.real==2); CU_ASSERT(v.C.imag==4); complexVector vc = complex_vector_conj(v); CU_ASSERT(vc.A.real==1); CU_ASSERT(vc.A.imag==-2); CU_ASSERT(vc.B.real==1); CU_ASSERT(vc.B.imag==2); CU_ASSERT(vc.C.real==2); CU_ASSERT(vc.C.imag==-4); }
struct Node* create_declarator_array(void) { struct Node* f0 = node_new(__DECLARATOR); const char* str = "kakikukeko"; char* iden = malloc(sizeof(*iden)); strcpy(iden, str); struct Node* n0 = node_new_leaf(__IDENTIFIER, (void*)iden); struct Complex* index = complex_new(10, 0); struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)index); node_link(f0, n0); node_link(f0, n1); return f0; }