-
Notifications
You must be signed in to change notification settings - Fork 1
/
twobitseq_test.c
84 lines (70 loc) · 2 KB
/
twobitseq_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include "twobitseq.h"
/*
#define TBS_TEST(x, t) if (twobitseq_test(x, sizeof(x) - 1)) { \
printf("Failed for " ##x "\n"); \
t = 1; \
}*/
#define TBS_TEST(x, t) if (twobitseq_test(#x, sizeof(#x) - 1)) { printf("failed for " #x "\n"); t = 1; };
#define TBS_TEST_FAIL(x, t) if (twobitseq_test(#x, sizeof(#x) - 1) == 0) { printf("should have failed for " #x "\n"); t = 1; };
int twobitseq_test(const char *x, size_t len)
{
// read all characters back from tbs
// make sure they are the same as x
twobitseq_t *tbs = NULL;
size_t i;
char c;
int fail = 0;
int ret;
ret = twobitseq_create(&tbs, x, len);
if (ret < 0 || tbs == NULL) {
printf("failed to create tbs\n");
return 1;
}
for(i=0; i < len; i++) {
c = twobitseq_read_next_or_last_as_char(tbs);
if (c != x[i]) {
printf("[%s] expected %c but got %c at position %zd\n", x, x[i], c, i);
fail = 1;
goto end;
}
}
// read a little bit more after the end
for(i=0; i < 5; i++) {
c = twobitseq_read_next_or_last_as_char(tbs);
if (c != x[len - 1]) {
printf("[%s] expected %c but got %c for after last char\n", x, x[i], c);
fail = 1;
goto end;
}
}
end:
twobitseq_free(tbs);
return fail;
}
int main(int argc, char **argv)
{
(void) argc;
(void) argv;
int fail = 0;
TBS_TEST(A, fail);
TBS_TEST(X, fail);
TBS_TEST(W, fail);
TBS_TEST(F, fail);
TBS_TEST(AAAAAAAAAAAAA, fail);
TBS_TEST(XXXXXXXXXXXXX, fail);
TBS_TEST(WWWWWWWWWWWWW, fail);
TBS_TEST(FFFFFFFFFFFFF, fail);
TBS_TEST(WWFFFFWWFFFFWX, fail);
TBS_TEST(FFWWWWFFWWWWFA, fail);
TBS_TEST(FFA, fail);
TBS_TEST(WWX, fail);
TBS_TEST_FAIL(AAY, fail);
printf("Ignore above error. It meant to do that\n");
if (fail) {
printf("Twobitseq tests failed!\n");
} else {
printf("Twobitseq tests passed!\n");
}
return fail;
}