forked from 131/lab3_test
68 lines
2.3 KiB
C
68 lines
2.3 KiB
C
#include <stdio.h>
|
||
#include "munit/munit.h"
|
||
#include "aux_lib.h"
|
||
#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 }
|
||
};
|
||
|
||
static const MunitSuite test_suite = {
|
||
(char*) "",
|
||
test_suite_tests,
|
||
NULL, // Вложенные наборы теÑ<C2B5>tov
|
||
1, // КоличеÑ<C2B5>тво прогонов
|
||
MUNIT_SUITE_OPTION_NONE
|
||
};
|
||
|
||
|
||
int
|
||
main(int argc, const char *argv[])
|
||
{
|
||
munit_suite_main(&test_suite, (void *) "auxiliary library test", argc, (char * const*) argv);
|
||
return 0;
|
||
}
|