void app_initialize(void) { static const UrosString turtle1 = { 7, "turtle1" }; static const UrosNodeConfig *const cfgp = &urosNode.config; unsigned i; /* Initialize the uROS system.*/ urosInit(); fifo_init(&rosoutQueue, 8); /* Initialize the turtle slots.*/ urosMutexObjectInit(&turtleCanSpawnLock); turtleCanSpawn = UROS_TRUE; turtle_init_pools(); for (i = 0; i < MAX_TURTLES; ++i) { turtle_init(&turtles[i], i); } /* Create the Node thread.*/ urosNodeCreateThread(); /* Spawn the first turtle.*/ turtle_spawn(&turtle1, 0.5f * SANDBOX_WIDTH, 0.5f * SANDBOX_HEIGHT, 0.0f); }
bool test_forward_and_rounding() { cout << "Testing turtle_move_forward and rounding: " << endl; turtle t; turtle_init(&t, 500, 500, ""); for (int i = 0; i < 10; i++) { turtle_rotate_left (&t, 33); turtle_move_forward(&t,10); } if (t.x != -10 || t.y != -1) { display_result (__FILE__, __LINE__, testcount); return false; } cout << "Test " << testcount << " passed." << endl; testcount++; turtle_end(&t); cout << endl; return true; }
int main() { int koch = 3; turtle_init(2000, 2000); koch_start(5); turtle_save_bmp("koch.bmp"); turtle_cleanup(); printf("%d\n", koch); return 0; }
bool test_pen () { cout << "Testing turtle_pen_up and turtle_pen_down:" << endl; turtle t; /* * This code one of the problems with using structures. Even though * we want all the modification of the turtle structure to happen through * our functions, the compiler will not prevent someone from changing * the contents directly. * This is helpful for my test program, but bad in general. */ t.x = 99; t.y = 99; t.angle = 99; t.penDown = false; t.writeToFile = true; turtle_init(&t, 500,500, NULL); turtle_pen_up(&t); if (t.penDown) { display_result (__FILE__, __LINE__, testcount); return false; } cout << "Test " << testcount << " passed." << endl; testcount++; turtle_pen_down(&t); if (!t.penDown) { display_result (__FILE__, __LINE__, testcount); return false; } cout << "Test " << testcount << " passed." << endl; testcount++; turtle_end(&t); cout << endl; return true; }
bool test_svg_output() { cout << "Testing svg output. You need to validate this test by hand." << endl; turtle t; turtle_init(&t, 500, 500, "part1.svg"); turtle_pen_down(&t); for (int i = 0; i < 5; i++) { turtle_move_forward(&t, 50); turtle_rotate_right (&t, 144); } turtle_end(&t); return true; }
bool test_rotate() { cout << "Testing turtle_rotate_left and turtle_rotate_right:" << endl; turtle t; turtle_init(&t, 500,500, NULL); turtle_rotate_left(&t, 90); if (t.angle != 90) { display_result (__FILE__, __LINE__, testcount); return false; } cout << "Test " << testcount << " passed." << endl; testcount++; turtle_rotate_right(&t, 90); if (t.angle != 0) { display_result (__FILE__, __LINE__, testcount); return false; } cout << "Test " << testcount << " passed." << endl; testcount++; for (int i = 1; i <= 16; i++) { turtle_rotate_left(&t,45); int expected = (i*45) % 360; if (t.angle != expected) { display_result (__FILE__, __LINE__, testcount); return false; } } cout << "Test " << testcount << " passed." << endl; testcount++; for (int i = 1; i <= 16; i++) { turtle_rotate_right(&t,45); int expected = (360 - ((i*45) % 360)) % 360; if (t.angle != expected) { display_result (__FILE__, __LINE__, testcount); return false; } } cout << "Test " << testcount << " passed." << endl; testcount++; cout << endl; turtle_end(&t); return true; }