Advertisement
Guest User

bla

a guest
Jan 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.74 KB | None | 0 0
  1. int run_ref_tests(char methode[]){
  2.     int* tab0 = create_array(0);
  3.     int* tab1 = create_array(1);
  4.     int* tab2 = create_array(2);
  5.     int* tab3 = create_array(100);
  6.     int* tab4 = create_array(1000);
  7.     int* tab5 = create_array(10000);
  8.     int* tab6 = create_array(1);
  9.  
  10.     fill_random_array(tab1, 1, 1000);
  11.     fill_random_array(tab2, 2, 1000);
  12.     fill_random_array(tab3, 100, 1000);
  13.     fill_random_array(tab4, 1000, 1000);
  14.     fill_random_array(tab5, 10000, 10000);
  15.     /*tab6[0] = 0;*/
  16.  
  17.  
  18.     if (methode == "selec"){
  19.         selection_sort(tab0, 0);
  20.         selection_sort(tab1, 1);
  21.         selection_sort(tab2, 2);
  22.         selection_sort(tab3, 100);
  23.         selection_sort(tab4, 1000);
  24.         selection_sort(tab5, 10000);
  25.         selection_sort(tab6, 1);
  26.  
  27.     }
  28.  
  29.     else if (methode == "quick"){
  30.         quick_sort(tab0, 0);
  31.         quick_sort(tab1, 1);
  32.         quick_sort(tab2, 2);
  33.         quick_sort(tab3, 100);
  34.         quick_sort(tab4, 1000);
  35.         quick_sort(tab5, 10000);
  36.         quick_sort(tab6, 1);
  37.  
  38.     }
  39.  
  40.     else if (methode == "insert"){
  41.         insertion_sort(tab0, 0);
  42.         insertion_sort(tab1, 1);
  43.         insertion_sort(tab2, 2);
  44.         insertion_sort(tab3, 100);
  45.         insertion_sort(tab4, 1000);
  46.         insertion_sort(tab5, 10000);
  47.         insertion_sort(tab6, 1);
  48.     }
  49.  
  50.  
  51.     if (sorted_check(tab0, 0) == 0){
  52.         printf("tableau vide incorrect avec la methode %s\n", methode);
  53.         return 0;
  54.     }
  55.     else if (sorted_check(tab1, 1) == 0){
  56.         printf("tableau avec 1 élément incorrect avec la methode %s\n", methode);
  57.         return 0;
  58.     }
  59.     else if (sorted_check(tab2, 2) == 0){
  60.         printf("tableau avec 2 éléments incorrect avec la methode %s\n", methode);
  61.         return 0;
  62.     }
  63.     else if (sorted_check(tab3, 100) == 0){
  64.         printf("tableau avec 100 éléments incorrect avec la methode %s\n", methode);
  65.         return 0;
  66.     }
  67.     else if (sorted_check(tab4, 1000) == 0){
  68.         printf("tableau avec 1000 éléments incorrect avec la methode %s\n", methode);
  69.         return 0;
  70.     }
  71.     else if (sorted_check(tab5, 10000) == 0){
  72.         printf("tableau 10 000 éléments incorrect avec la methode %s\n", methode);
  73.         return 0;
  74.     }
  75.     else if (sorted_check(tab6, 1) == 0){
  76.         printf("tableau de 1 élément avec un 0 incorrect avec la methode %s\n", methode);
  77.         return 0;
  78.     }
  79.  
  80.     return 1;
  81.  
  82. }
  83.  
  84. int menu(int m){
  85.     switch (m){
  86.         case 1: run_ref_tests("selec");
  87.         break;
  88.         case 2: run_ref_tests("quick");
  89.         break;
  90.         case 3: run_ref_tests("insert");
  91.         break;
  92.         default:
  93.             return 0;
  94.     }
  95.     printf("ok\n");
  96. }
  97.  
  98. int main(int argc, char *argv[]) {
  99.  
  100.     srand(time(NULL));
  101.     char m;
  102.     /* tableau de référence */
  103.     int* tab_ref = NULL;
  104.     /* tableau de travail */
  105.     int* tab = NULL;
  106.  
  107.    
  108.     printf("Choisissez une méthode de tri:\n1. Selection\n2. Quick-Sort\n3. Insertion\n");
  109.     scanf("%d", m);
  110.    
  111.     menu(m);
  112.  
  113.  
  114.     /* libération des tableaux */
  115.     free(tab);
  116.     tab = NULL;
  117.     free(tab_ref);
  118.     tab_ref = NULL;
  119.  
  120.     return EXIT_SUCCESS;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement