Exemplo n.º 1
0
void test_save_algorithm() {
    test_initiated("save_algorithm");
    
    Algorithm * algo = algorithm_for_string("R Uw 2Fw3 D' M2 x L2 y' z2");
    
    FILE * temp = tmpfile();
    assert(temp != NULL);
    
    save_algorithm(algo, temp);
    fseek(temp, 0, SEEK_SET);
    Algorithm * loaded = load_algorithm(temp);
    
    if (!loaded) {
        puts("Error: failed to load algorithm at all!");
    }
    if (loaded->type != AlgorithmTypeContainer) {
        puts("Error: invalid type for loaded algorithm.");
    }
    
    test_algorithm_equality(algo, loaded);
    
    fclose(temp);
    
    algorithm_free(algo);
    algorithm_free(loaded);
    test_completed();
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    /* parse command line args */
    for (int i = 1; i+1 < argc; i+=2) {
	if (strcmp(argv[i], "-m") == 0)
	    mazefile = argv[i+1];

	else if (strcmp(argv[i], "-a") == 0)
	    algfile = argv[i+1];
    }

    /* initialize program */
    if (algfile && !load_algorithm(algfile, &algorithm)) {
	fprintf(stderr, "error loading algorithm\n");
	return 1;
    }

    if (!parse_maze(mazefile, &maze)) {
	fprintf(stderr, "error reading maze file\n");
	return 1;
    }

    view = create_view();

    controller = create_controller(
	&view, &maze, &mouse, &algorithm);

    /* run program */
    while(!controller.quit) {
	do_command( &controller, getchar() );
    }

    /* cleanup */
    view.destroy();

    return 0;
}