2023-03-25 04:17:47 +03:00
|
|
|
|
#include <stdio.h>
|
2025-11-22 03:22:24 -05:00
|
|
|
|
#include "munit/munit.h"
|
2023-03-25 04:17:47 +03:00
|
|
|
|
#include "aux_lib.h"
|
2025-11-22 03:22:24 -05:00
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
|
|
static MunitResult test_fibonacci_base(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(3), ==, 2);
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static MunitResult test_bit_count(const MunitParameter params[], void* fixture) {
|
|
|
|
|
|
munit_assert_int(bit_count(0), ==, 0);
|
|
|
|
|
|
munit_assert_int(bit_count(1), ==, 1);
|
|
|
|
|
|
munit_assert_int(bit_count(3), ==, 2);
|
|
|
|
|
|
munit_assert_int(bit_count(8), ==, 1);
|
|
|
|
|
|
munit_assert_int(bit_count(255), ==, 8);
|
|
|
|
|
|
munit_assert_int(bit_count(0xFFFFFFFF), ==, 32);
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MunitResult test_fibonacci_advanced(const MunitParameter params[], void* fixture) {
|
|
|
|
|
|
munit_assert_int(fibonacci(10), ==, 55);
|
|
|
|
|
|
munit_assert_int(fibonacci(20), ==, 6765);
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MunitResult test_sum_odd(const MunitParameter params[], void* fixture) {
|
|
|
|
|
|
int arr[] = {1, 2, 3, 4, 5};
|
|
|
|
|
|
munit_assert_true(sum_is_odd(arr, 5));
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MunitResult test_sum_even(const MunitParameter params[], void* fixture) {
|
|
|
|
|
|
int arr[] = {1, 2, 3, 4, 5, 1};
|
|
|
|
|
|
munit_assert_false(sum_is_odd(arr, 6));
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MunitTest test_suite_tests[] = {
|
|
|
|
|
|
{ (char*) "fibonacci base cases", test_fibonacci_base, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
|
|
|
|
|
|
{ (char*) "fibonacci advanced cases", test_fibonacci_advanced, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
|
|
|
|
|
|
{ (char*) "sum odd array", test_sum_odd, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
|
|
|
|
|
|
{ (char*) "sum even array", test_sum_even, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
|
|
|
|
|
|
{ (char*) "bit count", test_bit_count, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
|
|
|
|
|
|
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
|
|
|
|
|
|
};
|
2023-03-25 04:17:47 +03:00
|
|
|
|
|
|
|
|
|
|
static const MunitSuite test_suite = {
|
2025-11-22 03:22:24 -05:00
|
|
|
|
(char*) "",
|
|
|
|
|
|
test_suite_tests,
|
|
|
|
|
|
NULL, // Вложенные наборы теÑ<C2B5>tov
|
|
|
|
|
|
1, // КоличеÑ<C2B5>тво прогонов
|
|
|
|
|
|
MUNIT_SUITE_OPTION_NONE
|
2023-03-25 04:17:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-22 03:22:24 -05:00
|
|
|
|
|
2023-03-25 04:17:47 +03:00
|
|
|
|
int
|
|
|
|
|
|
main(int argc, const char *argv[])
|
|
|
|
|
|
{
|
2025-11-22 03:22:24 -05:00
|
|
|
|
munit_suite_main(&test_suite, (void *) "auxiliary library test", argc, (char * const*) argv);
|
|
|
|
|
|
return 0;
|
2023-03-25 04:17:47 +03:00
|
|
|
|
}
|