-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paramatised tests but not every combination #80
Comments
Jab2870
changed the title
Paramatised tests but not every iteration
Paramatised tests but not every combination
Jan 6, 2022
To add to this, currently I have a single test function that defines the array like |
Outsider comment; feel free to ignore. I can think of four options:
static char* double_params[] = {
(char*) "1 2", (char*) "2 4", (char*) "0 0", /* ... */ NULL
};
static MunitResult
test_double(const MunitParameter params[], void* user_data) {
char* pair_string;
char* endp;
long int input, output;
pair_string = munit_parameters_get(params, "pair");
input = strtol(pair_string, &endp, 0);
output = strtol(endp, NULL, 0);
/* ... */
}
static MunitTest test_suite_tests[] = {
{ (char*) "/example/double/1", test_double_1, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ (char*) "/example/double/2", test_double_2, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ (char*) "/example/double/0", test_double_0, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ (char*) "/example/double/20", test_double_20, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ (char*) "/example/double/-5", test_double_m5, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
// ...
};
static void*
test_setup_1(const MunitParameter params[], void* user_data) {
(void) params;
return (void*)(&(tests[0]));
}
static void*
test_setup_2(const MunitParameter params[], void* user_data) {
(void) params;
return (void*)(&(tests[1]));
}
static void*
test_setup_m5(const MunitParameter params[], void* user_data) {
(void) params;
return (void*)(&(tests[4]));
}
static MunitTest test_suite_tests[] = {
{ (char*) "/example/double/1", test_double, test_setup_1, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ (char*) "/example/double/2", test_double, test_setup_2, NULL, MUNIT_TEST_OPTION_NONE, NULL },
// ...
{ (char*) "/example/double/-5", test_double, test_setup_m5, NULL, MUNIT_TEST_OPTION_NONE, NULL },
// ...
};
static MunitResult
test_double(const MunitParameter params[], void* user_data) {
int input, output;
int index = munit_rand_int_range(0, 4);
input = tests[index][0];
output = tests[index][1];
munit_logf(MUNIT_LOG_INFO, "testing %i, %i", input, output);
/* ... */
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am quite new to munit and c programming in general so my apologies in advance
if I'm missing something.
I would like something similar to paramatised tests but without necessarily
running through every combination.
So, let's say I was testing a function called double.
I might want to call my test function with the following "parameters":
The first being the input and the second being the expected output.
The output might be something like this:
Thanks in advance
The text was updated successfully, but these errors were encountered: