1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include <criterion/criterion.h>
#include <stdlib.h>
#include <string.h>
void reverse_alternate(const char *string, char *result);
void tester(const char *string, char *expected);
Test(reverse_alternate, Sample_Tests) {
tester("Did it work?", "Did ti work?");
tester("I really hope it works this time...", "I yllaer hope ti works siht time...");
tester("Reverse this string, please!", "Reverse siht string, !esaelp");
tester("Have a beer", "Have a beer");
tester(" ", "");
}
void tester(const char *string, char *expected) {
size_t length = strlen(string);
char submitted[length + 1];
memset(submitted, '@', length + 1);
reverse_alternate(string, submitted);
cr_assert( !strcmp(submitted, expected),
"< Incorrect Result >\n \nstring = \"%s\"\n \nSubmitted: \"%s\"\nExpected: \"%s\"\n \n",
string, submitted, expected
);
}
|