diff --git a/perso/box.c b/perso/box.c index 848969dafa5466772d33816f6a467c92bcd3e565..2a21e0d1a10d5ba0d0b5501ad8457fc66ac424cd 100644 --- a/perso/box.c +++ b/perso/box.c @@ -8,23 +8,23 @@ * * * * * * * * * * * * * * * * * * */ -Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1) { - Box* temp_box = malloc(sizeof(Box)); +Box new_box(double new_x0, double new_y0, double new_x1, double new_y1) { + Box temp_box; if (new_x0 > new_x1) { - temp_box -> x0 = new_x1; - temp_box -> x1 = new_x0; + temp_box.x0 = new_x1; + temp_box.x1 = new_x0; } else { - temp_box -> x0 = new_x0; - temp_box -> x1 = new_x1; + temp_box.x0 = new_x0; + temp_box.x1 = new_x1; } if (new_y0 > new_y1) { - temp_box -> y0 = new_y1; - temp_box -> y1 = new_y0; + temp_box.y0 = new_y1; + temp_box.y1 = new_y0; } else { - temp_box -> y0 = new_y0; - temp_box -> y1 = new_y1; + temp_box.y0 = new_y0; + temp_box.y1 = new_y1; } @@ -32,7 +32,7 @@ Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1) { } -Box* divide_in_four(Box* box) { +Box* divide_in_four(Box box) { /* (x0 ; y0) @@ -49,13 +49,13 @@ Box* divide_in_four(Box* box) { */ - Box* b0 = new_box(box -> x0, box -> y0, box -> x1/2, box -> y1/2); - Box* b1 = new_box(box -> x1/2, box -> y0, box -> x1, box -> y1/2); - Box* b2 = new_box(box -> x0, box -> y1/2, box -> x1/2, box -> y1); - Box* b3 = new_box(box -> x1/2, box -> y1/2, box -> x1, box -> y1); + Box b0 = new_box(box.x0, box.y0, box.x1/2.0, box.y1/2.0); + Box b1 = new_box(box.x1/2.0, box.y0, box.x1, box.y1/2.0); + Box b2 = new_box(box.x0, box.y1/2.0, box.x1/2.0, box.y1); + Box b3 = new_box(box.x1/2.0, box.y1/2.0, box.x1, box.y1); // pointeur ou pas? - Box* sub_boxes[] = malloc(4 * sizeof(Box*)); + Box* sub_boxes = malloc(4 * sizeof(Box)); sub_boxes[0] = b0; sub_boxes[1] = b1; sub_boxes[2] = b2; @@ -105,33 +105,26 @@ void print_box(Box box) { void tests_box() { printf("TESTS BOX : \n"); - Box* b1 = new_box(0.0, 0.0, 3.0, 3.0); + Box b1 = new_box(0.0, 0.0, 3.0, 3.0); Box* b2 = divide_in_four(b1); - tests_box_new(b1); tests_box_divide(b2); tests_box_include(b1); - free(b1); free(b2); - printf("\n"); } -void tests_box_new(Box* b1) { - TEST(b1 != NULL); -} - -void tests_box_divide(Box* b2) { - // COMPLETER APRES AVOIR FINI DIVIDE() - printf("bla"); +void tests_box_divide(Box* b) { + Box box_test = new_box(1.5, 0.0, 3.0, 1.5); + TEST(box_test.x0 == b[1].x0 && box_test.x1 == b[1].x1 && box_test.y0 == b[1].y0 && box_test.y1 == b[1].y1); } -void tests_box_include(Box* b1) { +void tests_box_include(Box b1) { Vector* vector = new_vec(1.0, 2.0); - TEST(is_inside(*b1, *vector)); + TEST(is_inside(b1, *vector)); free(vector); } \ No newline at end of file diff --git a/perso/box.h b/perso/box.h index 7fcd14d2ae6b51f107f569fe1adcc5f183ee167e..48a5a5d988f91ac1ce01b0030c448f162b7de7f9 100644 --- a/perso/box.h +++ b/perso/box.h @@ -23,10 +23,10 @@ typedef struct __box { * * * * * * * * * * * * * * * * */ // crée une nouvelle box -Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1); +Box new_box(double new_x0, double new_y0, double new_x1, double new_y1); // divise une box en quatre parties égales -Box* divide_in_four(Box* box); +Box* divide_in_four(Box box); // détérmine si une position est dans la box bool is_inside(Box box, Vector vector); @@ -39,8 +39,8 @@ void print_box(Box box); void tests_box(); -void tests_box_new(Box* b1); -void tests_box_divide(Box* b2); -void tests_box_include(Box* b1); +// void tests_box_new(Box b); +void tests_box_divide(Box* b); +void tests_box_include(Box b); #endif \ No newline at end of file diff --git a/perso/tests.h b/perso/tests.h new file mode 100644 index 0000000000000000000000000000000000000000..df1459f637fe8058df4a8df1ecac68270cbbab29 --- /dev/null +++ b/perso/tests.h @@ -0,0 +1,17 @@ +#ifndef __TESTS_H__ +#define __TESTS_H__ + + +#define TEST(x) \ + if (x) \ + PRT_OK else PRT_NOK + +// OK print en vert, error en rouge +#define PRT_OK printf("\t%s() : %sok%s\n", __func__, "\t[\x1B[32m", "\x1B[0m]"); +#define PRT_NOK printf("\t%s() : %serror%s\n", __func__, "\t[\x1B[31m", "\x1B[0m]"); + + + + + +#endif \ No newline at end of file