forked from 131/lab3_test
68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
#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;
|
|
}
|
|
|