diff --git a/Makefile b/Makefile index 407851d2168b65616b50d12407def12ec056bc54..4549cfa3264aa69df91cb300fe9f6f7cfe0a9e1b 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 1411080fe371f807f6d02577c02ba8b8c1002efb..53ba9c08ff76a9bc2e305ee5b2a98e302b1003e3 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();