From ded876b22b8052635bf07f56de915c321dea8580 Mon Sep 17 00:00:00 2001 From: "arnaud.devevey" <arnaud.de-vevey@etu.hesge.ch> Date: Fri, 31 May 2019 12:57:05 +0200 Subject: [PATCH] pause midi --- perso/Makefile | 2 +- perso/galaxy.c | 22 ++++++++++++++-------- perso/vector.c | 42 ++++++++++++++++++++++++++++++++++++++++-- perso/vector.h | 3 +++ 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/perso/Makefile b/perso/Makefile index 2a8fb43..4f2d1dc 100644 --- a/perso/Makefile +++ b/perso/Makefile @@ -25,7 +25,7 @@ vector.o : vector.c clean : - rm -f *.o $(EXE) + rm -f *.o galaxy diff --git a/perso/galaxy.c b/perso/galaxy.c index ac6d8bd..73a5bab 100644 --- a/perso/galaxy.c +++ b/perso/galaxy.c @@ -5,17 +5,17 @@ * Date : xx.06.2019 * * * * * * * * * * * * * * * * */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <stdint.h> -#include <time.h> -#include <libgen.h> +// #include <stdio.h> +// #include <stdlib.h> +// #include <string.h> +// #include <math.h> +#include <assert.h> +// #include <stdint.h> +// #include <time.h> +// #include <libgen.h> #include "galaxy.h" - #include "quadtree.h" @@ -44,6 +44,12 @@ int main(int argc, char **argv) { destruction_galaxie(); */ + tests_vector(); + // tests_star(); + // tests_box(); + // tests_quadtree(); + + // tests_galaxy(); // on crée une étoile en (0;0) qui a comme masse 10^6 * masse solaire diff --git a/perso/vector.c b/perso/vector.c index 2074d6e..7e3dea0 100644 --- a/perso/vector.c +++ b/perso/vector.c @@ -1,8 +1,22 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <assert.h> + #include "vector.h" + +/* * * * * * * * * * * * * * * * * +* * +* --- TESTS --- * +* * +* * * * * * * * * * * * * * * * */ + + + + + + /* * * * * * * * * * * * * * * * * * * * --- FONCTIONS --- * @@ -38,10 +52,11 @@ Vector* sub_vec(const Vector* const v1, const Vector* const v2) { return temp_vec; } - +/* Vector* mul_vec(const Vector* const v1, const Vector* const v2) { } +*/ Vector* scal_mul_vec(const Vector* const v1, const double lambda) { @@ -55,7 +70,7 @@ Vector* scal_mul_vec(const Vector* const v1, const double lambda) { double norm(const Vector* const v1) { - return sqrt(pow(v1 -> x, 2.0) + pow(v1 -> x, 2.0)); + return sqrt(pow(v1 -> x, 2.0) + pow(v1 -> y, 2.0)); } @@ -72,4 +87,27 @@ double distance(const Vector* const v1, const Vector* const v2) { void print_vec(const Vector* const v) { printf("\tprint_vec() : x = %f \ty = %f \n", v -> x, v -> y); +} + + + +void tests_vector() { + Vector* v1 = new_vec(1.0, 2.0); + Vector* v2 = new_vec(3.0, 5.0); + + assert(v1 != NULL && v2 != NULL); + + Vector* v_tests = new_vec(4.0, 7.0); + assert(add_vec(v1, v2) == v_tests); + + v_tests -> x = -2.0; + v_tests -> y = -3.0; + assert(sub_vec(v1, v2) == v_tests); + + assert(norm(v1) == sqrt(5)); + + v_tests -> x = 2.0; + v_tests -> y = 3.0; + double norm_tests = norm(v_tests); + assert(distance(v1, v2) == norm_tests); } \ No newline at end of file diff --git a/perso/vector.h b/perso/vector.h index 80ba49c..386f65f 100644 --- a/perso/vector.h +++ b/perso/vector.h @@ -47,4 +47,7 @@ double distance(const Vector* const v1, const Vector* const v2); void print_vec(const Vector* const v); +void tests_vector(); + + #endif \ No newline at end of file -- GitLab