1
0
forked from 131/lab3_test
This commit is contained in:
etrushko05
2025-11-22 03:22:24 -05:00
parent d8cd2b9316
commit 59d2d3e1cd
11 changed files with 154 additions and 9 deletions

BIN
aux_bin Executable file

Binary file not shown.

BIN
aux_bin.o Normal file

Binary file not shown.

View File

@@ -6,8 +6,18 @@
int
fibonacci(int nitem)
{
//YOUR_CODE
return 42;
if (nitem <= 0) return 0;
if (nitem == 1) return 1;
int prev = 0;
int curr = 1;
for (int i = 2; i <= nitem; i++) {
int next = prev + curr;
prev = curr;
curr = next;
}
return curr;
}
/*
@@ -17,6 +27,20 @@ fibonacci(int nitem)
bool
sum_is_odd(int *arr, int arrsz)
{
//YOUR_CODE
return false;
int sum = 0;
for (int i = 0; i < arrsz; i++) {
sum += arr[i];
}
return (sum % 2 != 0);
}
int bit_count(unsigned int number)
{
int count = 0;
while (number) {
count += number & 1;
number >>= 1;
}
return count;
}

View File

@@ -5,3 +5,5 @@ int fibonacci(int nitem);
bool sum_is_odd(int *arr, int arrsz);
int bit_count(unsigned int number);

BIN
aux_lib.o Normal file

Binary file not shown.

BIN
aux_test Executable file

Binary file not shown.

View File

@@ -1,15 +1,67 @@
#include <stdio.h>
#include "munit.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 = {
//FILL ME
(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 *) "string library test", argc, (char * const*) argv);
return 0;
munit_suite_main(&test_suite, (void *) "auxiliary library test", argc, (char * const*) argv);
return 0;
}

BIN
aux_test.o Normal file

Binary file not shown.

BIN
munit/example Executable file

Binary file not shown.

BIN
munit/munit.o Normal file

Binary file not shown.

67
str_test.c Normal file
View File

@@ -0,0 +1,67 @@
#include <stdio.h>
#include "munit.h"
#include "str_lib.h"
static MunitResult
test_mystrlen(const MunitParameter params[], void * data)
{
munit_assert_true(mystrlen("") == 0);
munit_assert_true(mystrlen("333") == 3);
munit_assert_true(mystrlen("helloworld") == 10);
return MUNIT_OK;
}
static MunitResult
test_mystr_idx(const MunitParameter params[], void * data)
{
munit_assert_true(mystr_idx("", "") == 0);
munit_assert_true(mystr_idx("h", "h") == 0);
munit_assert_true(mystr_idx("ah", "h") == 1);
munit_assert_true(mystr_idx("ah", "hh") == -1);
munit_assert_true(mystr_idx("ahh", "hh") == 1);
char *cap = "London is the capital of Great Britan";
munit_assert_true(mystr_idx(cap, "python") == -1);
munit_assert_true(mystr_idx(cap, "London") == 0);
munit_assert_true(mystr_idx(cap, "o") == 1);
munit_assert_true(mystr_idx(cap, "is") == 7);
return MUNIT_OK;
}
static MunitResult
test_mystr_idx_largestr(const MunitParameter params[], void * data)
{
munit_assert_true(mystr_idx("", "LARGE STRING") == -1);
munit_assert_true(mystr_idx("ARGE_STRING", "LARGE STRING") == -1);
munit_assert_true(mystr_idx("ARGE STRING", "LARGE STRING") == -1);
munit_assert_true(mystr_idx("RGE STRING", "LARGE STRING") == -1);
return MUNIT_OK;
}
#define TEST_ITEM(func) {#func, func, NULL, NULL, MUNIT_TEST_OPTION_NONE }
static MunitTest test_suite_tests[] = {
TEST_ITEM(test_mystrlen),
TEST_ITEM(test_mystr_idx),
TEST_ITEM(test_mystr_idx_largestr),
//TEST_ITEM(test_pvector_init),
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static const MunitSuite test_suite = {
(char *) "",
test_suite_tests,
NULL,
1,
MUNIT_SUITE_OPTION_NONE
};
int
main(int argc, const char *argv[])
{
munit_suite_main(&test_suite, (void *) "string library test", argc, (char * const*) argv);
return 0;
}