This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
prog-104-p-02-2030/tests/test_basics.c
T
lucas e56b334e85
Tests Basics avec Criterion / test (push) Failing after 6s
test
2026-04-02 14:55:12 +02:00

50 lines
1.5 KiB
C

#include <criterion/criterion.h>
#include <stdio.h>
#include "../Chains_across_the_Island/Fundamentals/basics/basics.h"
// Test pour list_append
Test(basics_suite, test_append) {
struct list *l = NULL;
l = list_append(l, 42);
cr_assert_not_null(l, "La liste ne doit pas être NULL après le premier ajout.");
cr_assert_eq(l->data, 42, "La donnée du premier nœud doit être 42.");
l = list_append(l, 7);
cr_assert_not_null(l->next, "Le deuxième nœud doit exister.");
cr_assert_eq(l->next->data, 7, "La donnée du deuxième nœud doit être 7.");
list_destroy(l);
}
// Test pour list_count
Test(basics_suite, test_count) {
struct list *l = NULL;
cr_assert_eq(list_count(l), 0, "Une liste vide doit avoir une taille de 0.");
l = list_append(l, 10);
l = list_append(l, 20);
l = list_append(l, 30);
cr_assert_eq(list_count(l), 3, "La liste doit contenir 3 éléments.");
printf("%i\n", list_count(l));
list_destroy(l);
}
// Test pour list_insert
Test(basics_suite, test_insert) {
struct list *l = NULL;
// Insertion dans une liste vide
int res1 = list_insert(&l, 0, 100);
cr_assert_eq(res1, 0, "L'insertion à l'index 0 doit réussir.");
cr_assert_eq(l->data, 100, "La valeur insérée doit être 100.");
// Insertion hors limite
int res2 = list_insert(&l, 5, 200);
cr_assert_eq(res2, 1, "L'insertion hors limite doit échouer et renvoyer 1.");
list_destroy(l);
}