END_TEST START_TEST (test_FunctionDefinition_getArguments) { const ASTNode_t *math; ASTNode_t* math1 = SBML_parseFormula("lambda(x, y, x^y)"); FunctionDefinition_setMath(FD, math1 ); ASTNode_free(math1); fail_unless( FunctionDefinition_getNumArguments(FD) == 2 ); math = FunctionDefinition_getArgument(FD, 0); fail_unless( math != NULL ); fail_unless( ASTNode_isName(math) ); fail_unless( !strcmp(ASTNode_getName(math), "x") ); fail_unless( ASTNode_getNumChildren(math) == 0 ); math = FunctionDefinition_getArgument(FD, 1); fail_unless( math != NULL ); fail_unless( ASTNode_isName(math) ); fail_unless( !strcmp(ASTNode_getName(math), "y") ); fail_unless( ASTNode_getNumChildren(math) == 0 ); fail_unless( FunctionDefinition_getArgument(FD, 0) == FunctionDefinition_getArgumentByName(FD, "x") ); fail_unless( FunctionDefinition_getArgument(FD, 1) == FunctionDefinition_getArgumentByName(FD, "y") ); }
void ev_alter_tree_structure(Model_t *m, ASTNode_t **node_p, ASTNode_t *parent, int child_order, copied_AST *cp_AST){ ASTNode_t *zero_node; ASTNode_t *node, *next_node; ASTNode_t *pc_eq, *pc_cd, *times_node, *and_node, *not_node; unsigned int i, j; int p; ASTNode_t *arg_node_list[MAX_ARG_NUM]; unsigned int arg_node_num; FunctionDefinition_t *fd; ASTNode_t *fd_arg; ASTNode_t *fd_body; node = *node_p; for(i=0; i<ASTNode_getNumChildren(node); i++){ next_node = ASTNode_getChild(node, i); if(ASTNode_getNumChildren(node) == 1 && ASTNode_getType(node) == AST_MINUS){ zero_node = ASTNode_create(); ASTNode_setType(zero_node, AST_REAL); ASTNode_setReal(zero_node, 0); ASTNode_replaceChild(node, 0, zero_node); ASTNode_addChild(*node_p, next_node); }else{ ev_alter_tree_structure(m, &next_node, *node_p, i, cp_AST); } } if(ASTNode_getType(node) == AST_FUNCTION){ arg_node_num = ASTNode_getNumChildren(node); for(i=0; i<arg_node_num; i++){ arg_node_list[i] = ASTNode_getChild(node, i); } for(i=0; i<Model_getNumFunctionDefinitions(m); i++){ fd = (FunctionDefinition_t*)ListOf_get(Model_getListOfFunctionDefinitions(m), i); fd_body = (ASTNode_t*)FunctionDefinition_getBody(fd); if(strcmp(FunctionDefinition_getId(fd), ASTNode_getName(node)) == 0){ fd_body = ASTNode_deepCopy(fd_body); cp_AST->ast[cp_AST->num_of_copied_AST++] = fd_body; for(j=0; j<FunctionDefinition_getNumArguments(fd); j++){ fd_arg = (ASTNode_t*)FunctionDefinition_getArgument(fd, j); ASTNode_replaceArgument(fd_body, (char*)ASTNode_getName(fd_arg), arg_node_list[j]); } /* check_AST(fd_body, NULL); */ if(parent != NULL){ ASTNode_replaceChild(parent, child_order, fd_body); }else{ *node_p = fd_body; } node = *node_p; break; } } } if(ASTNode_getType(node) == AST_FUNCTION_PIECEWISE){ ASTNode_setType(node, AST_PLUS); ASTNode_setName(node, NULL); times_node = ASTNode_createWithType(AST_TIMES); pc_eq = ASTNode_getRightChild(node); ASTNode_addChild(times_node, pc_eq); if(ASTNode_getNumChildren(node) > 3){ and_node = ASTNode_createWithType(AST_LOGICAL_AND); ASTNode_addChild(times_node, and_node); for(p=(int)ASTNode_getNumChildren(node)-2; p >= 1; p = p-2){ pc_cd = ASTNode_getChild(node, p); not_node = ASTNode_createWithType(AST_LOGICAL_NOT); ASTNode_addChild(not_node, pc_cd); ASTNode_addChild(and_node, not_node); } ASTNode_reduceToBinary(and_node); }else{ pc_cd = ASTNode_getChild(node, 1); not_node = ASTNode_createWithType(AST_LOGICAL_NOT); ASTNode_addChild(not_node, pc_cd); ASTNode_addChild(times_node, not_node); } ASTNode_replaceChild(node, ASTNode_getNumChildren(node)-1, times_node); for(p=ASTNode_getNumChildren(node)-2; p >= 1; p = p-2){ times_node = ASTNode_createWithType(AST_TIMES); pc_eq = ASTNode_getChild(node, p-1); pc_cd = ASTNode_getChild(node, p); ASTNode_addChild(times_node, pc_eq); ASTNode_addChild(times_node, ASTNode_deepCopy(pc_cd)); ASTNode_removeChild(node, p); ASTNode_replaceChild(node ,p-1, times_node); } ASTNode_reduceToBinary(node); } return; }