init projet
This commit is contained in:
128
tp3/TP3/main.c
Normal file
128
tp3/TP3/main.c
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "alloc.h"
|
||||
#include "queuetest.h"
|
||||
#include "stacktest.h"
|
||||
#include "testprint.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
// Basculez à 1 les valeurs ci-dessous pour activer les tests correspondants.
|
||||
#define TEST_STACK_BASIC 1
|
||||
#define TEST_SORT_STACK 0
|
||||
#define TEST_COPY_STACK 1
|
||||
#define TEST_HANOI 1
|
||||
|
||||
#define TEST_QUEUE_BASIC 0
|
||||
#define TEST_COPY_QUEUE 0
|
||||
#define TEST_SORT_QUEUE 0
|
||||
|
||||
int main(void) {
|
||||
// Initialisation du générateur de nombres aléatoires
|
||||
srandom(time(NULL));
|
||||
|
||||
#if TEST_STACK_BASIC
|
||||
stack *p, *r, *s;
|
||||
printf("\nTest de random et de tower\n\n");
|
||||
p = random_stack(42, 999);
|
||||
r = tower_stack(42);
|
||||
s = tower_stack(42);
|
||||
print_stacks(0, 2, p, r);
|
||||
|
||||
printf("\nTest de push\n\n");
|
||||
for (int i = 0; i < 24; i++) // pour provoquer un grow
|
||||
push(i, s);
|
||||
print_stacks(0, 2, r, s);
|
||||
|
||||
printf("\nTest de pop\n\n");
|
||||
delete_stack(s);
|
||||
s = tower_stack(42);
|
||||
for (int i = 0; i < 40; i++) // pour provoquer un shrink
|
||||
pop(s);
|
||||
print_stacks(0, 2, r, s);
|
||||
|
||||
delete_stack(p);
|
||||
delete_stack(r);
|
||||
delete_stack(s);
|
||||
#endif
|
||||
|
||||
#if TEST_COPY_STACK
|
||||
stack *p1, *p2;
|
||||
|
||||
printf("\nTest de copy_stack\n\n");
|
||||
p1 = random_stack(42, 999);
|
||||
p2 = copy_stack(p1);
|
||||
print_stacks(0, 2, p1, p2);
|
||||
delete_stack(p1);
|
||||
delete_stack(p2);
|
||||
#endif
|
||||
|
||||
#if TEST_SORT_STACK
|
||||
printf("\nTest de bubble_sort_stack\n\n");
|
||||
stack *t = random_stack(42, 999);
|
||||
printf("Avant le tri\n\n");
|
||||
print_stacks(0, 1, t);
|
||||
bubble_sort_stack(t);
|
||||
printf("Après le tri\n\n");
|
||||
print_stacks(0, 1, t);
|
||||
delete_stack(t);
|
||||
#endif
|
||||
|
||||
#if TEST_HANOI
|
||||
printf("\nTest de Hanoi\n\n");
|
||||
hanoi(3);
|
||||
#endif
|
||||
|
||||
#if TEST_QUEUE_BASIC
|
||||
queue *p, *r, *s;
|
||||
printf("\nTest de random et de mountain\n\n");
|
||||
p = random_queue(42, 50);
|
||||
r = mountain_queue(21);
|
||||
s = mountain_queue(21);
|
||||
print_queue(p);
|
||||
print_queue(r);
|
||||
|
||||
printf("\nTest de enqueue\n\n");
|
||||
for (int i = 0; i < 24; i++) // pour provoquer un grow
|
||||
enqueue(99 - i, s);
|
||||
print_queue(r);
|
||||
print_queue(s);
|
||||
|
||||
printf("\nTest de dequeue\n\n");
|
||||
delete_queue(s);
|
||||
s = mountain_queue(21);
|
||||
for (int i = 0; i < 40; i++) // pour provoquer un shrink
|
||||
dequeue(s);
|
||||
print_queue(r);
|
||||
print_queue(s);
|
||||
|
||||
delete_queue(p);
|
||||
delete_queue(r);
|
||||
delete_queue(s);
|
||||
#endif
|
||||
|
||||
#if TEST_COPY_QUEUE
|
||||
queue *p1, *p2;
|
||||
|
||||
printf("\nTest de copy_queue\n\n");
|
||||
p1 = random_queue(42, 99);
|
||||
p2 = copy_queue(p1);
|
||||
print_queue(p1);
|
||||
print_queue(p2);
|
||||
delete_queue(p1);
|
||||
delete_queue(p2);
|
||||
#endif
|
||||
|
||||
#if TEST_SORT_QUEUE
|
||||
printf("\nTest de select_sort_queue\n\n");
|
||||
queue *t = random_queue(5, 100);
|
||||
printf("Avant le tri\n");
|
||||
print_queue(t);
|
||||
select_sort_queue(t);
|
||||
printf("\nAprès le tri\n");
|
||||
print_queue(t);
|
||||
delete_queue(t);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user