Self-test implementations.
90 {
91
92 int **
L, **B, j, l1, l2;
93
94 char *s1 = "ACGGTGTCGTGCTATGCTGATGCTGACTTATATGCTA";
95 char *s2 = "CGTTCGGCTATCGTACGTTCTATTCTATGATTTCTAA";
96 char *lcs;
97
98 l1 = strlen(s1);
99 l2 = strlen(s2);
100
101 L = (
int **)
calloc(l1+1,
sizeof(
int *));
102 B = (
int **)
calloc(l1+1,
sizeof(
int *));
103
105 perror("calloc: ");
106 exit(1);
107 }
108 if (!B) {
109 perror("calloc: ");
110 exit(1);
111 }
112 for (j = 0; j <= l1; j++) {
113 L[j] = (
int *)
calloc(l2+1,
sizeof(
int));
115 perror("calloc: ");
116 exit(1);
117 }
118 B[j] = (
int *)
calloc(l2+1,
sizeof(
int));
120 perror("calloc: ");
121 exit(1);
122 }
123 }
124
127
128 assert(
L[l1][l2] == 27);
129 assert(strcmp(lcs, "CGTTCGGCTATGCTTCTACTTATTCTA") == 0);
130
131 printf("S1: %s\tS2: %s\n", s1, s2);
132 printf(
"LCS len:%3d\n",
L[l1][l2]);
133 printf("LCS: %s\n", lcs);
134
136 for (j = 0; j <= l1; j++)
140
141 printf("All tests have successfully passed!\n");
142}
char * lcsbuild(const char *s1, int l1, int l2, int **L, int **B)
@breif Builds the LCS according to B using a traceback approach
Definition: lcs.c:59
void lcslen(const char *s1, const char *s2, int l1, int l2, int **L, int **B)
@breif Computes LCS between s1 and s2 using a dynamic-programming approach
Definition: lcs.c:27
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition: malloc_dbg.h:26