//fill the error board void fill_error(void) { struct element *p = state.element; if(!error.element) error.element = fill_element(error.element,"name","yaomoon" ); fill_element(error.element,"name","yaomingyue" ); }
//fill the state board void fill_state(void) { struct element *p = state.element; if(!state.element) state.element = fill_element(state.element,"name","yaomoon" ); fill_element(state.element,"name","yaomingyue" ); }
/** * This function takes a tfst_match list that represents a match. It turns it into * a tfst_simple_match_list element and inserts it into to the main tfst_simple_match_list, * according to the match filtering rules. */ void add_tfst_match(struct locate_tfst_infos* infos,struct tfst_match* m) { struct tfst_simple_match_list element; fill_element(infos,&element,m); if (element.m.end_pos_in_token==-1) { /* If the match was in fact completely text independent, then we reject it */ return; } //error("match from token %d.%d to %d.%d\n",element.m.start_pos_in_token,element.m.start_pos_in_char, // element.m.end_pos_in_token,element.m.end_pos_in_char); if (infos->output_policy==IGNORE_OUTPUTS) { /* The simplest case */ infos->matches=add_element_to_list(infos,infos->matches,&element); } else { explore_match_to_get_outputs(infos,m,&element); } }
TEST(PRIORITY_QUEUE,DEQUEUE){ ELEMENT_RESULT ele_result = dequeue(424234); EXPECT_EQ(ele_result.result.code,TICKET_INVALID);//or does not exist EXPECT_EQ(strcmp(ele_result.element.item,""),0); EXPECT_EQ(ele_result.element.priority,0); WELCOME_PACKET packet = create_queue(); ele_result = dequeue(packet.ticket); EXPECT_EQ(ele_result.result.code,QUEUE_IS_EMPTY); ELEMENT e; char temp[MAX_STRING_LENGTH]; for(int i = 0; i < MAXIMUM_NUMBER_OF_ELEMENTS_IN_A_QUEUE; i++){ snprintf(temp,MAX_STRING_LENGTH,"%d",i); e = fill_element(temp,4); enqueue(e,packet.ticket); } for(int i = 0; i < MAXIMUM_NUMBER_OF_ELEMENTS_IN_A_QUEUE; i++){ ELEMENT_RESULT item = dequeue(packet.ticket); e = item.element; snprintf(temp,MAX_STRING_LENGTH,"%d",i); EXPECT_EQ(strcmp(e.item,temp),0); } ELEMENT_RESULT r = dequeue(packet.ticket); EXPECT_EQ(r.result.code,QUEUE_IS_EMPTY); RESULT res = delete_queue(packet.ticket); EXPECT_EQ(res.code,SUCCESS); ELEMENT_RESULT result = dequeue(packet.ticket); EXPECT_EQ(r.result.code,QUEUE_IS_EMPTY); }
TEST(PRIORITY_QUEUE,ENQUEUE){ //try a bad ticket numbers ELEMENT e = {"test",9}; RESULT r = enqueue(e,-313213); EXPECT_EQ(r.code, TICKET_INVALID); r = enqueue(e,0); EXPECT_EQ(r.code, TICKET_INVALID); //create a valid queue WELCOME_PACKET packet = create_queue(); //try bad priority e = fill_element("test",-3); r = enqueue(e,packet.ticket); EXPECT_EQ(r.code, ITEM_INVALID); //try bad priority e = fill_element("test",11); r = enqueue(e,packet.ticket); EXPECT_EQ(r.code, ITEM_INVALID); //fill queue e = fill_element("test",4); for(int i = 0; i < MAXIMUM_NUMBER_OF_ELEMENTS_IN_A_QUEUE; i++){ r = enqueue(e,packet.ticket); EXPECT_EQ(get_size(packet.ticket).size,i+1); EXPECT_EQ(r.code, SUCCESS); } //add one to many to the queue r = enqueue(e,packet.ticket); EXPECT_EQ(r.code, QUEUE_IS_FULL); //delete the queue r = delete_queue(packet.ticket); EXPECT_EQ(r.code,SUCCESS); //try to enque on a deleted queue r = enqueue(e,packet.ticket); EXPECT_EQ(r.code, TICKET_INVALID); /////////////////////////////////////////////////////////// // CHECK FOR THE CORRECT ENQUEUEUING BASED ON PRIORITIES // srand(time(NULL)); packet = create_queue(); // fill queue with max elements with random priorities from // [0-10], then compare the insertion number as the base of the // comparision char temp[1024]; for(int i = 0; i < MAXIMUM_NUMBER_OF_ELEMENTS_IN_A_QUEUE; i++){ snprintf(temp,1024,"%d",i); e = fill_element(temp,rand()%10); r = enqueue(e,packet.ticket); EXPECT_EQ(get_size(packet.ticket).size,i+1); EXPECT_EQ(r.code, SUCCESS); } ELEMENT_RESULT er; ELEMENT_RESULT last; last = dequeue(packet.ticket); for(int i = 1; i < MAXIMUM_NUMBER_OF_ELEMENTS_IN_A_QUEUE; i++){ er = dequeue(packet.ticket); EXPECT_TRUE(last.element.priority >= er.element.priority); if(last.element.priority == er.element.priority) EXPECT_TRUE(atoi(last.element.item) < atoi(er.element.item)); last = er; } }