void test_move_over() { /* Set up */ world_t* world = world_create(5); /* Test case 1 - A is top of stack */ move_over(world, 1, 2); assert(world->position_blocks_top[1] == NULL && world->position_blocks_bottom[1] == NULL); assert(world->position_blocks_top[2]->value == 1 && world->position_blocks_bottom[2]->value == 2); /* Test case 2 - A in middle of stack, B on top */ move_over(world, 3, 4); move_over(world, 2, 4); assert(block_get_stack(block_get(world, 1)) == 1); assert(block_get_stack(block_get(world, 2)) == 4 && block_get_stack(block_get(world, 3)) == 4 && block_get_stack(block_get(world, 4)) == 4 ); assert(world->position_blocks_top[4]->value == 2 && world->position_blocks_bottom[4]->value == 4); /* Test case 3 - A and B on same stack */ move_over(world, 3, 4); assert(block_get_stack(block_get(world, 2)) == 4 && block_get_stack(block_get(world, 3)) == 4 && block_get_stack(block_get(world, 4)) == 4 ); assert(world->position_blocks_top[4]->value == 2 && world->position_blocks_bottom[4]->value == 4); /* Tear down */ world_delete(&world); }
int main(void){ pos* table = init_table(); build_positions(table, 10); move_onto(table, 9,1); move_over(table, 8,1); move_over(table, 7,1); move_over(table, 6,1); pile_over(table, 8,6); pile_over(table, 8,5); move_over(table, 2,1); move_over(table, 4,9); display_all(table); return 0; }
void run_cmd(Stack stacks[N], int locations[N], char cmd[M]) { char action[M], type[M]; int a, b; sscanf (cmd, "%s %d %s %d\n", action, &a, type, &b); if (a == b || locations[a] == locations[b]) return; if (!strcmp (action, "move") && !strcmp (type, "onto")) move_onto (stacks, locations, a, b); else if (!strcmp (action, "move") && !strcmp (type, "over")) move_over (stacks, locations, a, b); else if (!strcmp (action, "pile") && !strcmp (type, "onto")) pile_onto (stacks, locations, a, b); else if (!strcmp (action, "pile") && !strcmp (type, "over")) pile_over (stacks, locations, a, b); else return; }