Self-test implementations.
100 {
101
102 int **
L, **B, j, l1, l2;
103
104 char *s1 = "ACGGTGTCGTGCTATGCTGATGCTGACTTATATGCTA";
105 char *s2 = "CGTTCGGCTATCGTACGTTCTATTCTATGATTTCTAA";
106 char *lcs;
107
108 l1 = strlen(s1);
109 l2 = strlen(s2);
110
111 L = (
int **)
calloc(l1+1,
sizeof(
int *));
112 B = (
int **)
calloc(l1+1,
sizeof(
int *));
113
115 perror("calloc: ");
116 exit(1);
117 }
118 if (!B) {
119 perror("calloc: ");
120 exit(1);
121 }
122 for (j = 0; j <= l1; j++) {
123 L[j] = (
int *)
calloc(l2+1,
sizeof(
int));
125 perror("calloc: ");
126 exit(1);
127 }
128 B[j] = (
int *)
calloc(l2+1,
sizeof(
int));
130 perror("calloc: ");
131 exit(1);
132 }
133 }
134
137
138 assert(
L[l1][l2] == 27);
139 assert(strcmp(lcs, "CGTTCGGCTATGCTTCTACTTATTCTA") == 0);
140
141 printf("S1: %s\tS2: %s\n", s1, s2);
142 printf(
"LCS len:%3d\n",
L[l1][l2]);
143 printf("LCS: %s\n", lcs);
144
146 for (j = 0; j <= l1; j++)
147 {
149 }
152
153 printf("All tests have successfully passed!\n");
154}
char * lcsbuild(const char *s1, int l1, int l2, int **L, int **B)
Builds the LCS according to B using a traceback approach.
Definition lcs.c:64
void lcslen(const char *s1, const char *s2, int l1, int l2, int **L, int **B)
Computes LCS between s1 and s2 using a dynamic-programming approach.
Definition lcs.c:30
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26