From fc1b6068aa0dfa4e60a93442f6ceab3be65cb1ea Mon Sep 17 00:00:00 2001 From: lpaucot_uclouvain <laurent.paucot@student.uclouvain.be> Date: Wed, 18 Mar 2020 11:12:16 +0100 Subject: [PATCH] Test,run,makefile ok --- Makefile | 6 +++--- test.c | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 407851d..4549cfa 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all : run run : run.o test.o - gcc -o run run.o test.o + gcc -o run run.o test.o -I${HOME}/local/include -lcunit -L${HOME}/local/lib run.o : run.c @@ -9,11 +9,11 @@ run.o : run.c test.o : test.c run.h - gcc -o test.o -c test.c -I${HOME}/local/include -W -Wall + gcc -o test.o -c test.c -I${HOME}/local/include -W -Wall -lcunit clean : rm -rf *.o mrproper: clean - rm -rf hello + rm -rf run diff --git a/test.c b/test.c index 1411080..53ba9c0 100644 --- a/test.c +++ b/test.c @@ -4,20 +4,20 @@ #include <CUnit/CUnit.h> #include <CUnit/TestRun.h> #include <CUnit/CUError.h> +#include <CUnit/Basic.h> void test_is_div(void){ CU_ASSERT_TRUE(is_div(14,7)); } +void test_is_prime(void){ + CU_ASSERT_TRUE(is_prime(13)); +} +void test_is_not_prime(void){ + CU_ASSERT_FALSE(is_prime(14)); +} -int main(){ - - if (CUE_SUCCESS != CU_initialize_registry()) - { - return CU_get_error(); - } - - int setup(void){ +int setup(void){ return 0; } @@ -26,6 +26,13 @@ int main(){ return 0; } +int main(){ + + if (CUE_SUCCESS != CU_initialize_registry()) + { + return CU_get_error(); + } + CU_pSuite pSuite = NULL; @@ -37,7 +44,9 @@ int main(){ return CU_get_error(); } - if (NULL == CU_add_test(pSuite,"test_is_div",test_is_div)) + if (NULL == CU_add_test(pSuite,"test_is_div",test_is_div) || + NULL == CU_add_test(pSuite, "test_is_prime",test_is_prime) || + NULL == CU_add_test(pSuite, "test_is_not_prime",test_is_not_prime)) { CU_cleanup_registry(); return CU_get_error(); -- GitLab