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

64 lines
1.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include "munit.h"
#include "bit_lib.h" // Подключаем наш новый модуль
/* --- Тест для bit_count --- */
static MunitResult
test_bit_count(const MunitParameter params[], void* fixture)
{
// 1. Тест на ноль
// 0 в двоичной ...0000
munit_assert_int(bit_count(0), ==, 0);
// 2. Тест на 1
// 1 в двоичной ...0001
munit_assert_int(bit_count(1), ==, 1);
// 3. Тест на степень двойки
// 8 в двоичной ...1000
munit_assert_int(bit_count(8), ==, 1);
// 1024 в двоичной ...10000000000
munit_assert_int(bit_count(1024), ==, 1);
// 4. Тест на число с несколькими битами
// 7 в двоичной ...0111
munit_assert_int(bit_count(7), ==, 3);
// 13 в двоичной ...1101
munit_assert_int(bit_count(13), ==, 3);
// 254 в двоичной ...11111110
munit_assert_int(bit_count(254), ==, 7);
// 5. Тест на 'все единицы' (для unsigned int, 32 бита)
// 0xFFFFFFFF (или 4294967295)
munit_assert_int(bit_count(0xFFFFFFFF), ==, 32);
return MUNIT_OK;
}
/* Массив тестов */
static MunitTest tests[] = {
{ "/test_bit_count", test_bit_count, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
/* Обязательный NULL-терминатор в конце массива */
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static const MunitSuite test_suite = {
"/bit_tests", /* Имя сюиты */
tests, /* Массив тестов */
NULL, /* Вложенные сюиты */
1, /* 1 итерация */
MUNIT_SUITE_OPTION_NONE /* Опции */
};
int
main(int argc, const char *argv[])
{
munit_suite_main(&test_suite, (void *) "bit library test", argc, (char * const*) argv);
return 0;
}