void test_seat(void) { CU_ASSERT(occupy_seat(1,1) == NO_ERROR); CU_ASSERT(occupy_seat(1,1) == ERROR_SEAT_ALREADY_TAKEN); CU_ASSERT(clear_seat(1,1) == NO_ERROR); CU_ASSERT(clear_seat(1,1) == ERROR_SEAT_ALREADY_EMPTY); }
void open_the_shop(){ int flag = 1, next_customer, i; printf("\nThe Shop is now open\n"); while( flag ){ //sleep(2); timer = timer + 1; for( i = 0 ; i < barber_count && barber[i].value == 0 ; i++ ) barber[i].time++; // barber status is recorded for( i = 0 ; i < wait_customer_limit ; i++ ){ if( customer[i].value > 0 ) customer[i].time++; // customer waiting status is recorded } clear_seat(timer); sleep(2); next_customer = random()%9 + 1; printf("\n\t\t<--------Customer %d entered, cutting time = %d\n",timer, next_customer); sleep(1); check_the_q(next_customer); /* printf("Barber Seat status : \n"); for( i = 1 ; i < barber_count ; i++ ) printf("%6d",barber[i].time); printf("\n"); */ sleep(1); printf("\n---------------------------------------------------------------------------------------"); printf("\n\t\t\t\t\t\t\t\tTimer = %d\n",timer); printf("\nBarber Seat time status : \n"); for( i = 1 ; i < barber_count ; i++ ) printf("%6d",barber[i].value); usleep(100); /* printf("Customer Waiting seat status : \n"); for( i = 0 ; i < wait_customer_limit ; i++ ) printf("%6d",customer[i].time); */ sleep(1); printf("\nCustomer Burst Time : \n"); for( i = 0 ; i < wait_customer_limit ; i++ ) printf("%6d",customer[i].value); printf("\n---------------------------------------------------------------------------------------"); printf("\n\n\n"); //sleep(1); for( i = 0 ; i < barber_count ; i++ ){ if( barber[i].time < timer || barber[i].value == 0 ){ barber[i].time = timer; barber[i].value = 0; barber[i].pos = 0; check_the_q(0); } } } }