1
0
forked from 131/lab3_test
Files
lab3_test/aux_test.c
2025-11-01 03:04:24 +03:00

71 lines
2.4 KiB
C

#include <stdio.h>
#include "munit.h"
#include "aux_lib.h"
#include <stdbool.h> // Для bool, true, false
/* --- Тест для fibonacci --- */
static MunitResult
test_fibonacci(const MunitParameter params[], void* fixture)
{
// Проверяем базовые случаи
munit_assert_int(fibonacci(0), ==, 0);
munit_assert_int(fibonacci(1), ==, 1);
munit_assert_int(fibonacci(2), ==, 1);
// Проверяем несколько значений из последовательности
munit_assert_int(fibonacci(5), ==, 5);
munit_assert_int(fibonacci(10), ==, 55);
munit_assert_int(fibonacci(13), ==, 233);
return MUNIT_OK;
}
/* --- Тест для sum_is_odd --- */
static MunitResult
test_sum_is_odd(const MunitParameter params[], void* fixture)
{
// 1. Тест на нечетную сумму
int arr_odd[] = {1, 2, 4}; // Сумма = 7
munit_assert_true(sum_is_odd(arr_odd, 3));
// 2. Тест на четную сумму
int arr_even[] = {1, 2, 3}; // Сумма = 6
munit_assert_false(sum_is_odd(arr_even, 3));
// 3. Тест на пустой массив
int arr_empty[] = {}; // Сумма = 0 (четное)
munit_assert_false(sum_is_odd(arr_empty, 0));
// 4. Тест на один нечетный элемент
int arr_single_odd[] = {7}; // Сумма = 7
munit_assert_true(sum_is_odd(arr_single_odd, 1));
return MUNIT_OK;
}
/* Массив тестов */
static MunitTest tests[] = {
{ "/test_fibonacci", test_fibonacci, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ "/test_sum_is_odd", test_sum_is_odd, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
/* Обязательный NULL-терминатор в конце массива */
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static const MunitSuite test_suite = {
//FILL ME
"/aux_tests", /* Имя сюиты */
tests, /* Массив тестов */
NULL, /* Вложенные сюиты */
1, /* 1 итерация */
MUNIT_SUITE_OPTION_NONE /* Опции */
};
int
main(int argc, const char *argv[])
{
/* Меняем "string library test" на "aux library test" для понятности */
munit_suite_main(&test_suite, (void *) "aux library test", argc, (char * const*) argv);
return 0;
}