| 1 | /* tests.c - some tests for functions in scythe */ |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | #include "../scythe.h" |
| 7 | |
| 8 | #define TEST_INIT int iii, ppp=0, passed=0, failed=0, checked=0; |
| 9 | #define TEST(test, name) if (!(test)) { \ |
| 10 | fprintf(stderr, "FAILED TEST '%s'\n", name); \ |
| 11 | failed++; \ |
| 12 | } else { \ |
| 13 | printf("PASSED TEST '%s'\n", name); \ |
| 14 | passed++; \ |
| 15 | } checked++; \ |
| 16 | |
| 17 | #define TEST_ARRAY(array1, array2, n, name) for (iii = 0; iii < n; iii++) { \ |
| 18 | ppp = 0; \ |
| 19 | if (array1[iii] != array2[iii]) { \ |
| 20 | fprintf(stderr, "FAILED TEST '%s'\n", name); \ |
| 21 | ppp = 1; failed++; \ |
| 22 | break; \ |
| 23 | } \ |
| 24 | } \ |
| 25 | if (ppp == 0) { \ |
| 26 | passed++; \ |
| 27 | printf("PASSED TEST '%s'\n", name); \ |
| 28 | } \ |
| 29 | checked++; \ |
| 30 | |
| 31 | #define TEST_CLOSE printf("\ntests: %d\npassed: %d\nfailed: %d\n", checked, passed, failed); |
| 32 | |
| 33 | void test_score_sequence(void) { |
| 34 | char *seqa = "ATCGATCGATCGATCGATCGATCG"; |
| 35 | char *seqb = "AACGATCGATCGATCGATCGATCG"; |
| 36 | int cmp1[] = {1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; |
| 37 | int *cmp1_t = calloc(24, sizeof(*cmp1_t)); |
| 38 | score_sequence(cmp1_t, seqa, seqb, strlen(seqa)); |
| 39 | |
| 40 | TEST_INIT; |
| 41 | TEST_ARRAY(cmp1, cmp1_t, 24, "score_sequence"); |
| 42 | |
| 43 | TEST(sum(score_sequence(cmp1_t, seqa, seqb, strlen(seqa)), strlen(seqa)) == 22, "sum of score_sequence"); |
| 44 | |
| 45 | free(cmp1_t); |
| 46 | TEST_CLOSE; |
| 47 | } |
| 48 | |
| 49 | int main(int argc, char *argv[]) { |
| 50 | test_score_sequence(); |
| 51 | return 0; |
| 52 | } |