correction
Tests Basics avec Criterion / test (push) Successful in 5s

This commit is contained in:
2026-04-02 15:52:42 +02:00
parent 7b93a83737
commit f5c181b822
3 changed files with 121 additions and 4 deletions
@@ -2,6 +2,7 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
struct list *list_append(struct list *l, int e)
{
struct list *tmp = l;
@@ -30,7 +31,7 @@ size_t list_count(struct list *l){
tmp = tmp->next;
}
return nbr_nodes;
return nbr_nodes + 1;
}
@@ -161,7 +162,7 @@ void list_print(struct list *l){
}
printf("\n");
}
/*
int main(void)
{
struct list *l = NULL;
@@ -174,10 +175,13 @@ int main(void)
// l = [1] -> [2] -> [3]
list_insert(&l, 1, 99); // l = [1] -> [99] -> [2] -> [3], and list_insert returns 0
list_insert(&l, 9, 99); // list unchanged, returns 1
list_print(l);
list_count(NULL); // 0
printf("count : %li\n",list_count(l)); // 3
list_destroy(l);
return 0;
}
*/
Binary file not shown.
+114 -1
View File
@@ -1,4 +1,7 @@
#include <criterion/criterion.h>
#include <criterion/internal/assert.h>
#include <criterion/internal/test.h>
#include <stddef.h>
#include <stdio.h>
#include "../Chains_across_the_Island/Fundamentals/basics/basics.h"
@@ -26,7 +29,7 @@ Test(basics_suite, test_count) {
l = list_append(l, 10);
l = list_append(l, 20);
l = list_append(l, 30);
printf("%i\n", list_count(l));
//printf("%i\n", list_count(l));
cr_assert_eq(list_count(l), 3, "La liste doit contenir 3 éléments.");
// printf("%i\n", list_count(l));
list_destroy(l);
@@ -47,3 +50,113 @@ Test(basics_suite, test_insert) {
list_destroy(l);
}
//Test pour list_get
Test(basics_suite, test_get){
struct list *l = NULL;
l = list_append(l, 30); // l = [30] -> NULL
l = list_append(l, 20); // l = [20] -> [30] -> NULL
l = list_append(l, 10); // l = [10] -> [20] -> [30] -> NULL
struct list *rslt = list_get(l,0);
cr_assert_eq(rslt->data, 10, "pointer to node with data=10");
rslt = list_get(l, 2);
cr_assert_eq(rslt->data, 30, "pointer to node with data=30");
rslt = list_get(l, 5);
cr_assert_null(rslt, "Poit doit etre null");
list_destroy(l);
list_destroy(rslt);
}
//Test list_find
Test(basics_suite, test_find){
struct list *l = NULL;
l = list_append(l, 3);
l = list_append(l, 7);
l = list_append(l, 1);
struct list *rslt = list_find(l, 7);
cr_assert_eq(rslt->data, 7, "pointer to node with data=7");
rslt = list_find(l, 42);
cr_assert_null(rslt, "pointeur doit etre null");
list_destroy(l);
list_destroy(rslt);
}
//Test list_delete_at
Test(basics_suite, test_delete_at){
struct list *l = NULL;
l = list_append(l, 30);
l = list_append(l, 20);
l = list_append(l, 10);
struct list *rslt = NULL;
rslt = list_delete_at(&l, 1); // returns pointer to node with data=20, l = [10] -> [30]
cr_assert_eq(rslt->data, 20, "La data du noeud supprimé doit etre de 20");
size_t count = 0;
count = list_count(l);
cr_assert_eq(count, 2, "La taille de la liste doit etre de 2");
rslt = list_get(l, 0);
cr_assert_eq(rslt->data, 10, "La data du noeud 1 doit etre de 10");
rslt = list_get(l, 1);
cr_assert_eq(rslt->data, 30, "La data du noeud 2 doit etre de 30");
rslt = list_get(l, 3);
cr_assert_null(rslt, "Le pointeur doit etre null");
list_destroy(l);
list_destroy(rslt);
}
//Test list_remove
Test(basics_suite, test_list_remove){
struct list *l = NULL;
l = list_append(l, 7);
l = list_append(l, 3);
l = list_append(l, 7);
l = list_append(l, 1);
int rm = 0;
struct list *tmp = l;
rm = list_remove(&l, 7); // returns 1, l = [1] -> [3] -> [7]
cr_assert_eq(rm, 1, "Le noeud 7 doit etre supprimé");
tmp = list_get(l, 0);
cr_assert_eq(tmp->data, 1, "Le noeud 1 a changé !");
tmp = list_get(l, 1);
cr_assert_eq(tmp->data, 3, "Le noeud 2 doit etre egal a 3");
tmp = list_get(l, 2);
cr_assert_eq(tmp->data, 7, "Le 3 eme noeud doit etre de 7");
l = tmp;
rm = list_remove(&l, 42); // returns 0, list unchanged
cr_assert_eq(rm, 0, "Doit renvoyer 0 !");
cr_assert_eq(l, tmp, "La liste ne doit pas changer");
list_destroy(l);
list_destroy(tmp);
}