forked from 131/lab3_test
initial commit
This commit is contained in:
67
str_test.c
Normal file
67
str_test.c
Normal 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user