-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
70 lines (54 loc) · 1.33 KB
/
test.c
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "str-flatten.h"
int failed = 0;
#define assert_equal_str(a, b) ({ \
if (0 != strcmp(a, b)) { \
fprintf(stderr, "Assertion failed: \"%s\" != \"%s\"\n", a, b); \
failed++; \
} \
})
int
main(void) {
const char *arr[] = {
"this",
"was",
"ripped",
"from",
"sphia"
};
char *flat = NULL;
flat = str_flatten(arr, 0, 5);
assert_equal_str("this was ripped from sphia", flat);
free(flat);
flat = str_flatten(arr, 1, 5);
assert_equal_str("was ripped from sphia", flat);
free(flat);
flat = str_flatten(arr, 2, 5);
assert_equal_str("ripped from sphia", flat);
free(flat);
flat = str_flatten(arr, 3, 5);
assert_equal_str("from sphia", flat);
free(flat);
flat = str_flatten(arr, 4, 5);
assert_equal_str("sphia", flat);
free(flat);
flat = str_flatten(arr, 0, 1);
assert_equal_str("this", flat);
free(flat);
flat = str_flatten(arr, 0, 2);
assert_equal_str("this was", flat);
free(flat);
flat = str_flatten(arr, 0, 3);
assert_equal_str("this was ripped", flat);
free(flat);
flat = str_flatten(arr, 0, 4);
assert_equal_str("this was ripped from", flat);
free(flat);
flat = str_flatten(arr, 0, 5);
assert_equal_str("this was ripped from sphia", flat);
free(flat);
return failed;
}