Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <CUnit/CUnit.h>
- int isocele(int a, int b, int c) {
- int estIsocele = 0;
- if(a==b || b==c || a==c) {
- estIsocele=1;
- }
- return estIsocele;
- }
- void testIsocele(void) {
- // triangle isocèle
- CU_ASSERT_TRUE(isocele(1,2,2));
- CU_ASSERT_TRUE(isocele(1,1,1));
- // triangle non isocèle
- CU_ASSERT_FALSE(isocele(1,2,3));
- }
- // La fonction va tester différentes chaines pour voir lesquelles passent
- void checkConforme() {
- // chaine normale avec que des minuscules
- CU_ASSERT_TRUE(rendreConforme("abc")=="*ABC*");
- // chaine vide
- CU_ASSERT_FALSE(rendreConforme("")=="");
- // chaine avec espace
- CU_ASSERT_TRUE(rendreConforme("abc efg")=="*ABC EFG*");
- // chaine avec majuscules et minuscules
- CU_ASSERT_TRUE(rendreConforme("aBc")=="*ABC*");
- // chaine avec majuscules
- CU_ASSERT_TRUE(rendreConforme("ABC")=="*ABC*");
- // chaine avec majuscules, minuscules et numériques
- CU_ASSERT_TRUE(rendreConforme("aBc123")=="*ABC123*");
- // chaine avec majuscules et numériques
- CU_ASSERT_TRUE(rendreConforme("ABC123")=="*ABC123*");
- // chaine avec minuscules et numériques
- CU_ASSERT_TRUE(rendreConforme("abc123")=="*ABC123*");
- // chaine avec numériques
- CU_ASSERT_TRUE(rendreConforme("123")=="*123*");
- // chaine avec caractères spéciaux +
- CU_ASSERT_TRUE(rendreConforme("abc+")=="*ABC+*");
- // chaine avec caractères spéciaux -
- CU_ASSERT_TRUE(rendreConforme("abc+")=="*ABC-*");
- // chaine avec caractères spéciaux /
- CU_ASSERT_TRUE(rendreConforme("a/bc")=="*A/BC*");
- // chaine avec caractères spéciaux $
- CU_ASSERT_TRUE(rendreConforme("$abc")=="*$ABC*");
- // chaine avec caractères spéciaux %
- CU_ASSERT_TRUE(rendreConforme("ab\%c")=="*AB\%c*");
- // chaine avec caractères spéciaux .
- CU_ASSERT_TRUE(rendreConforme("a.b.c")=="*A.B.C*");
- // chaine avec caractères spéciaux "espace"
- CU_ASSERT_TRUE(rendreConforme("abc ")=="*ABC *");
- // chaine avec plusieurs caractères spéciaux
- CU_ASSERT_TRUE(rendreConforme("a+b-c.d/e$f\%g ")=="*A+B-C.D/E$F\%G *");
- // chaine avec caractères spéciaux interdits
- CU_ASSERT_TRUE(rendreConforme("ab)cùd'e")=="*ABCDE*");
- }
- char* rendreConforme(char* chaine) {
- size_t longueurChaine = strlen(chaine)-1;
- // ON SUPPRIME LES CARACTERES INTERDITS et ON MET TOUT EN UPPER
- char* chaineNettoyee = (char*)malloc((longueurChaine+1)*sizeof(char));
- int i=0;
- int j=0;
- while(chaine[i])
- {
- chaine[i] = toupper(chaine[i]);
- if((chaine[i] >= 'A' && chaine[i] <= 'Z')
- || (chaine[i] >= '0' && chaine[i] <= '9')
- || chaine[i] == '+'
- || chaine[i] == '-'
- || chaine[i] == '.'
- || chaine[i] == '/'
- || chaine[i] == '$'
- || chaine[i] == '%'
- || chaine[i] == ' ')
- {
- chaineNettoyee[j] = chaine[i];
- j++;
- }
- i++;
- }
- // ON AJOUTE LES ETOILES
- // On récupère la longueur de la chaine rentrée
- size_t longueurChaineNettoyee = strlen(chaineNettoyee)-1;
- if (chaineNettoyee[longueurChaineNettoyee] == '\n')
- chaineNettoyee[longueurChaineNettoyee] = '\0';
- char* code39 = (char*)malloc((longueurChaineNettoyee+2)*sizeof(char));
- strcpy(code39,"*");
- strcat(code39,chaineNettoyee);
- strcat(code39, "*");
- return code39;
- }
- int main() {
- /*CU_initialize_registry();
- CU_pSuite suite = CU_add_suite("triangle_test", 0, 0);
- CU_add_test(suite, "iso_fun", testIsocele);
- CU_add_test(suite, "equilateral_fun", testEquilateral);
- CU_add_test(suite, "scalene_fun", testScalene);
- CU_add_test(suite, "rectangle_fun", testRectangle);
- CU_basic_run_tests();
- CU_cleanup_registry();*/
- //char* chaine = (char*)malloc(256*sizeof(char));
- printf("Chaine ?\n");
- char* chaine = (char*)malloc(256*sizeof(char));
- fgets(chaine, 256, stdin);
- char* leCode = rendreConforme(chaine);
- printf("%s\n", leCode);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement