Skip to content
Extraits de code Groupes Projets
Valider 2d05a946 rédigé par Giovanna Stefanelli's avatar Giovanna Stefanelli
Parcourir les fichiers

Update Fact_UnitTest.c

parent b53ae639
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #10099 en échec
// //
// Created by Gio on 23/04/2020. // Created on 22/04/2020.
// //
/* /*
* UNIT TEST WITH CUNIT * UNIT TEST WITH CUNIT
...@@ -34,7 +34,8 @@ bool is_div(unsigned long numbr, unsigned long i){ ...@@ -34,7 +34,8 @@ bool is_div(unsigned long numbr, unsigned long i){
} }
bool is_prime(unsigned long nbr) { bool is_prime(unsigned long nbr) {
for (unsigned long j = 2; j <= sqrt(nbr); j++) { unsigned long j;
for (j = 2; j <= sqrt(nbr); j++) {
if ((nbr % j) == 0) { // verify if i is the divider of nbr if ((nbr % j) == 0) { // verify if i is the divider of nbr
return (false); // i is a divider of nbr return (false); // i is a divider of nbr
} }
...@@ -52,25 +53,29 @@ bool is_prime(unsigned long nbr) { ...@@ -52,25 +53,29 @@ bool is_prime(unsigned long nbr) {
#define NEGATIVE -56056 #define NEGATIVE -56056
#define PRIME1 529973 #define PRIME1 529973
#define PRIME2 89 #define PRIME2 89
#define IMPAIR1 15
void test_is_div(void) { void test_is_div(void) {
CU_ASSERT_FALSE(is_div(IMPAIR, PAIR1) == false ); //False CU_ASSERT_FALSE(is_div(IMPAIR, PAIR1) == true ); //False
CU_ASSERT_FALSE(is_div(ZERO, PAIR2) == false); //False CU_ASSERT_FALSE(is_div(ZERO, PAIR2) == false); //False
CU_ASSERT_FALSE(is_div(PRIME1, IMPAIR) == false); //False CU_ASSERT_FALSE(is_div(PRIME1, IMPAIR1) == true); //False
CU_ASSERT_FALSE(is_div(NEGATIVE, PAIR1) == false); //False** CU_ASSERT_FALSE(is_div(NEGATIVE, PAIR1) == true); //False**
CU_ASSERT_FALSE(is_div(PRIME1, PAIR2) == false); //False CU_ASSERT_FALSE(is_div(PRIME1, PAIR2) == true); //False
CU_ASSERT_TRUE(is_div(PAIR1, PAIR2) == true); //True CU_ASSERT_TRUE(is_div(PAIR1, PAIR2) == true); //True
CU_ASSERT_TRUE(is_div(IMPAIR, PRIME2) == true); //True CU_ASSERT_TRUE(is_div(IMPAIR, PRIME2) == true); //True
} }
void test_is_prime(void) { void test_is_prime(void) {
CU_ASSERT_FALSE(is_prime(IMPAIR) == false); //False CU_ASSERT_FALSE(is_prime(IMPAIR) == true); //False
CU_ASSERT_FALSE(is_prime(ZERO) == false); //False
CU_ASSERT_TRUE(is_prime(PRIME1) == true); //True CU_ASSERT_FALSE(is_prime(ZERO) == false); //False
CU_ASSERT_FALSE(is_prime(NEGATIVE) == false); //False CU_ASSERT_TRUE(is_prime(PRIME1) == true); //True
CU_ASSERT_FALSE(is_prime(PAIR1) == false); //False CU_ASSERT_FALSE(is_prime(NEGATIVE) == false); //False
CU_ASSERT_FALSE(is_prime(PAIR1) == true); //False
} }
/* /*
...@@ -115,25 +120,26 @@ int main() { ...@@ -115,25 +120,26 @@ int main() {
} }
/* /*
* Add suite1 to registry * Add a suite to registry
*/ */
pSuite = CU_add_suite("Basic_Test_Suite1", init_suite, clean_suite); //pSuite = CU_add_suite("Basic_Test_Suite", init_suite, clean_suite);
pSuite = CU_add_suite("Basic_Test_Suite", NULL, NULL);
if (pSuite == NULL) { if (pSuite == NULL) {
CU_cleanup_registry(); CU_cleanup_registry();
return (CU_get_error()); return (CU_get_error());
} }
/* /*
* add test1 "is_div" to suite1 * add test "is_div" to suite
*/ */
if ((CU_add_test(pSuite, "\n\n……… Testing is_div function……..\n\n", test_is_div)) == NULL) if ((CU_add_test(pSuite, "\n\nTesting is_div function\n\n", test_is_div)) == NULL)
{ {
CU_cleanup_registry(); CU_cleanup_registry();
return (CU_get_error()); return (CU_get_error());
} }
/* /*
* add test1 "is_prime" to suite1 * add test "is_prime" to suite
*/ */
if ((CU_add_test(pSuite, "\n\n……… Testing is_prime function……..\n\n", test_is_prime)) == NULL) if ((CU_add_test(pSuite, "\n\nTesting is_prime function\n\n", test_is_prime)) == NULL)
{ {
CU_cleanup_registry(); CU_cleanup_registry();
return (CU_get_error()); return (CU_get_error());
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter