forked from 131/lab3_test
Update str_test.c
This commit is contained in:
59
str_test.c
59
str_test.c
@@ -0,0 +1,59 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "munit/munit.h"
|
||||||
|
#include "str_lib.h"
|
||||||
|
|
||||||
|
static MunitResult
|
||||||
|
test_mystrlen(const MunitParameter params[], void * data)
|
||||||
|
{
|
||||||
|
munit_assert_int(mystrlen(""), ==, 0);
|
||||||
|
munit_assert_int(mystrlen("333"), ==, 3);
|
||||||
|
munit_assert_int(mystrlen("helloworld"), ==, 10);
|
||||||
|
return MUNIT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MunitResult
|
||||||
|
test_mystr_idx(const MunitParameter params[], void * data)
|
||||||
|
{
|
||||||
|
munit_assert_int(mystr_idx("", ""), ==, 0);
|
||||||
|
munit_assert_int(mystr_idx("h", "h"), ==, 0);
|
||||||
|
munit_assert_int(mystr_idx("ah", "h"), ==, 1);
|
||||||
|
munit_assert_int(mystr_idx("ah", "hh"), ==, -1);
|
||||||
|
munit_assert_int(mystr_idx("ahh", "hh"), ==, 1);
|
||||||
|
char *cap = "London is the capital of Great Britan";
|
||||||
|
munit_assert_int(mystr_idx(cap, "python"), ==, -1);
|
||||||
|
munit_assert_int(mystr_idx(cap, "London"), ==, 0);
|
||||||
|
munit_assert_int(mystr_idx(cap, "o"), ==, 1);
|
||||||
|
munit_assert_int(mystr_idx(cap, "is"), ==, 7);
|
||||||
|
return MUNIT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MunitResult
|
||||||
|
test_mystr_idx_largestr(const MunitParameter params[], void * data)
|
||||||
|
{
|
||||||
|
munit_assert_int(mystr_idx("", "LARGE STRING"), ==, -1);
|
||||||
|
munit_assert_int(mystr_idx("ARGE_STRING", "LARGE STRING"), ==, -1);
|
||||||
|
munit_assert_int(mystr_idx("ARGE STRING", "LARGE STRING"), ==, -1);
|
||||||
|
munit_assert_int(mystr_idx("RGE STRING", "LARGE STRING"), ==, -1);
|
||||||
|
return MUNIT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_ITEM(func) {#func, func, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}
|
||||||
|
static MunitTest test_suite_tests[] = {
|
||||||
|
TEST_ITEM(test_mystrlen),
|
||||||
|
TEST_ITEM(test_mystr_idx),
|
||||||
|
TEST_ITEM(test_mystr_idx_largestr),
|
||||||
|
{ 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[])
|
||||||
|
{
|
||||||
|
return munit_suite_main(&test_suite, (void *) "string library test", argc, (char **)argv);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user