Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <CUnit/CUnit.h>
  6.  
  7. int isocele(int a, int b, int c) {
  8. int estIsocele = 0;
  9.  
  10. if(a==b || b==c || a==c) {
  11. estIsocele=1;
  12. }
  13.  
  14. return estIsocele;
  15. }
  16.  
  17. void testIsocele(void) {
  18. // triangle isocèle
  19. CU_ASSERT_TRUE(isocele(1,2,2));
  20. CU_ASSERT_TRUE(isocele(1,1,1));
  21.  
  22. // triangle non isocèle
  23. CU_ASSERT_FALSE(isocele(1,2,3));
  24.  
  25. }
  26.  
  27. // La fonction va tester différentes chaines pour voir lesquelles passent
  28. void checkConforme() {
  29. // chaine normale avec que des minuscules
  30. CU_ASSERT_TRUE(rendreConforme("abc")=="*ABC*");
  31. // chaine vide
  32. CU_ASSERT_FALSE(rendreConforme("")=="");
  33. // chaine avec espace
  34. CU_ASSERT_TRUE(rendreConforme("abc efg")=="*ABC EFG*");
  35. // chaine avec majuscules et minuscules
  36. CU_ASSERT_TRUE(rendreConforme("aBc")=="*ABC*");
  37. // chaine avec majuscules
  38. CU_ASSERT_TRUE(rendreConforme("ABC")=="*ABC*");
  39. // chaine avec majuscules, minuscules et numériques
  40. CU_ASSERT_TRUE(rendreConforme("aBc123")=="*ABC123*");
  41. // chaine avec majuscules et numériques
  42. CU_ASSERT_TRUE(rendreConforme("ABC123")=="*ABC123*");
  43. // chaine avec minuscules et numériques
  44. CU_ASSERT_TRUE(rendreConforme("abc123")=="*ABC123*");
  45. // chaine avec numériques
  46. CU_ASSERT_TRUE(rendreConforme("123")=="*123*");
  47. // chaine avec caractères spéciaux +
  48. CU_ASSERT_TRUE(rendreConforme("abc+")=="*ABC+*");
  49. // chaine avec caractères spéciaux -
  50. CU_ASSERT_TRUE(rendreConforme("abc+")=="*ABC-*");
  51. // chaine avec caractères spéciaux /
  52. CU_ASSERT_TRUE(rendreConforme("a/bc")=="*A/BC*");
  53. // chaine avec caractères spéciaux $
  54. CU_ASSERT_TRUE(rendreConforme("$abc")=="*$ABC*");
  55. // chaine avec caractères spéciaux %
  56. CU_ASSERT_TRUE(rendreConforme("ab\%c")=="*AB\%c*");
  57. // chaine avec caractères spéciaux .
  58. CU_ASSERT_TRUE(rendreConforme("a.b.c")=="*A.B.C*");
  59. // chaine avec caractères spéciaux "espace"
  60. CU_ASSERT_TRUE(rendreConforme("abc ")=="*ABC *");
  61. // chaine avec plusieurs caractères spéciaux
  62. CU_ASSERT_TRUE(rendreConforme("a+b-c.d/e$f\%g ")=="*A+B-C.D/E$F\%G *");
  63. // chaine avec caractères spéciaux interdits
  64. CU_ASSERT_TRUE(rendreConforme("ab)cùd'e")=="*ABCDE*");
  65. }
  66.  
  67. char* rendreConforme(char* chaine) {
  68.  
  69. size_t longueurChaine = strlen(chaine)-1;
  70.  
  71. // ON SUPPRIME LES CARACTERES INTERDITS et ON MET TOUT EN UPPER
  72.  
  73. char* chaineNettoyee = (char*)malloc((longueurChaine+1)*sizeof(char));
  74. int i=0;
  75. int j=0;
  76.  
  77. while(chaine[i])
  78. {
  79. chaine[i] = toupper(chaine[i]);
  80.  
  81. if((chaine[i] >= 'A' && chaine[i] <= 'Z')
  82. || (chaine[i] >= '0' && chaine[i] <= '9')
  83. || chaine[i] == '+'
  84. || chaine[i] == '-'
  85. || chaine[i] == '.'
  86. || chaine[i] == '/'
  87. || chaine[i] == '$'
  88. || chaine[i] == '%'
  89. || chaine[i] == ' ')
  90. {
  91. chaineNettoyee[j] = chaine[i];
  92. j++;
  93. }
  94. i++;
  95. }
  96.  
  97. // ON AJOUTE LES ETOILES
  98.  
  99. // On récupère la longueur de la chaine rentrée
  100.  
  101. size_t longueurChaineNettoyee = strlen(chaineNettoyee)-1;
  102. if (chaineNettoyee[longueurChaineNettoyee] == '\n')
  103. chaineNettoyee[longueurChaineNettoyee] = '\0';
  104. char* code39 = (char*)malloc((longueurChaineNettoyee+2)*sizeof(char));
  105. strcpy(code39,"*");
  106. strcat(code39,chaineNettoyee);
  107. strcat(code39, "*");
  108.  
  109. return code39;
  110. }
  111.  
  112. int main() {
  113.  
  114. /*CU_initialize_registry();
  115. CU_pSuite suite = CU_add_suite("triangle_test", 0, 0);
  116. CU_add_test(suite, "iso_fun", testIsocele);
  117. CU_add_test(suite, "equilateral_fun", testEquilateral);
  118. CU_add_test(suite, "scalene_fun", testScalene);
  119. CU_add_test(suite, "rectangle_fun", testRectangle);
  120. CU_basic_run_tests();
  121. CU_cleanup_registry();*/
  122.  
  123. //char* chaine = (char*)malloc(256*sizeof(char));
  124.  
  125. printf("Chaine ?\n");
  126.  
  127. char* chaine = (char*)malloc(256*sizeof(char));
  128.  
  129. fgets(chaine, 256, stdin);
  130.  
  131. char* leCode = rendreConforme(chaine);
  132.  
  133.  
  134.  
  135. printf("%s\n", leCode);
  136.  
  137. return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement