Skip to content
Extraits de code Groupes Projets

Project3

Ouvert Giovanna Stefanelli a demandé de fusionner stefanelli/projet3_first_pull_request:Project3 vers master
Comparer et Afficher la dernière version
6 fichiers
+ 71
46
Comparer les modifications
  • Côte à côte
  • En ligne
Fichiers
6
+ 24
18
//
// Created by Gio on 23/04/2020.
// Created on 22/04/2020.
//
/*
* UNIT TEST WITH CUNIT
@@ -34,7 +34,8 @@ bool is_div(unsigned long numbr, unsigned long i){
}
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
return (false); // i is a divider of nbr
}
@@ -52,25 +53,29 @@ bool is_prime(unsigned long nbr) {
#define NEGATIVE -56056
#define PRIME1 529973
#define PRIME2 89
#define IMPAIR1 15
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(PRIME1, IMPAIR) == false); //False
CU_ASSERT_FALSE(is_div(NEGATIVE, PAIR1) == false); //False**
CU_ASSERT_FALSE(is_div(PRIME1, PAIR2) == false); //False
CU_ASSERT_FALSE(is_div(PRIME1, IMPAIR1) == true); //False
CU_ASSERT_FALSE(is_div(NEGATIVE, PAIR1) == true); //False**
CU_ASSERT_FALSE(is_div(PRIME1, PAIR2) == true); //False
CU_ASSERT_TRUE(is_div(PAIR1, PAIR2) == true); //True
CU_ASSERT_TRUE(is_div(IMPAIR, PRIME2) == true); //True
}
void test_is_prime(void) {
CU_ASSERT_FALSE(is_prime(IMPAIR) == false); //False
CU_ASSERT_FALSE(is_prime(ZERO) == false); //False
CU_ASSERT_TRUE(is_prime(PRIME1) == true); //True
CU_ASSERT_FALSE(is_prime(NEGATIVE) == false); //False
CU_ASSERT_FALSE(is_prime(PAIR1) == 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(NEGATIVE) == false); //False
CU_ASSERT_FALSE(is_prime(PAIR1) == true); //False
}
/*
@@ -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) {
CU_cleanup_registry();
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();
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();
return (CU_get_error());
Chargement en cours