Skip to content

Commit

Permalink
ready t run the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymenkhs committed Mar 14, 2021
1 parent 6af8e9d commit 84b12b4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
28 changes: 25 additions & 3 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

#include "functions.h"

Expand All @@ -14,18 +15,18 @@ StoreTime * tab_execution(int * (* function)(long*, long), long * tab, int taill

for(int i=0; i<taille; i++){
results[i].num = tab[i];
printf("nombre %d\n\n", results[i].num);

ordered_tab = generer_bon_ordre(tab[i]);
results[i].time_ordered = execution_time(function, ordered_tab, taille);
free(ordered_tab);

inverse_tab = generer_ordre_inverse(tab[i]);
results[i].time_inverse = execution_time(function, inverse_tab, taille);
free(inverse_tab);

random_tab = generer_random(tab[i]);
results[i].time_random = execution_time(function, random_tab, taille);

free(ordered_tab);
free(inverse_tab);
free(random_tab);
}
return results;
Expand Down Expand Up @@ -98,3 +99,24 @@ int writeCSV(char * algorithm ,StoreTime * results, int taille){

return 1;
}

long * generer_tailles_tableaux(long debut, long fin, int *taille){
*taille = (int) (log((fin / debut)) / log(2) + 2) ;
long *tab = malloc((*taille) * sizeof(long));

long value = debut;
int i = 0;
while(value<=fin){
tab[i] = value;
value*=2;
i++;
}
return tab;
}

void print_tab(long * tab, long n){
for(int i=0; i<n; i++){
printf("%d ", tab[i]);
}
printf("\n\n\n");
}
3 changes: 3 additions & 0 deletions functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ long * generer_random(long n);
// ecrire les resultats dans un fichier csv
int writeCSV(char * algorithm ,StoreTime * results, int taille);

// generer les tableau des valleurs
long * generer_tailles_tableaux(long debut, long fin, int * taille);

#endif // base
12 changes: 8 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
int main(){
srand(time(NULL));

int (* fonctions [1])(long*, long) = {heapSort};
long *tab = NULL;
long debut = 50000, fin = 204800000;
int taille;

long tab[6] = {10, 100};
int (* fonctions [5])(long*, long) = {insertionSort, bubbleSort, mergeSort, quickSort, heapSort};

StoreTime *results = tab_execution(fonctions[0], tab, 2);
tab = generer_tailles_tableaux(debut, fin, &taille);

writeCSV("heapSort", results, 2);
StoreTime *results = tab_execution(fonctions[4], tab, taille);

writeCSV("heapSort", results, taille);

return EXIT_SUCCESS;
}

0 comments on commit 84b12b4

Please sign in to comment.