edit_distance: calculate edit distance between strings
[ccan] / ccan / edit_distance / test / run-types-short.c
1 /** @file
2  * Runnable tests for the edit_distance module using custom element and
3  * distance types.
4  *
5  * @copyright 2016 Kevin Locke <kevin@kevinlocke.name>
6  *            MIT license - see LICENSE file for details
7  */
8
9 #include <limits.h>             /* USHRT_MAX */
10
11 #include <ccan/array_size/array_size.h>
12 #include <ccan/tap/tap.h>
13
14 #define ed_elem unsigned short
15 #define ed_dist short
16 #define ED_HASH_ELEM(e) e
17 #define ED_HASH_MAX USHRT_MAX
18
19 #include <ccan/edit_distance/edit_distance.c>
20 #include <ccan/edit_distance/edit_distance_dl.c>
21 #include <ccan/edit_distance/edit_distance_lcs.c>
22 #include <ccan/edit_distance/edit_distance_lev.c>
23 #include <ccan/edit_distance/edit_distance_rdl.c>
24
25 int main(void)
26 {
27         const unsigned short src[] = { 0, 1, 2, 3 };
28         const unsigned short tgt[] = { 4, 2, 1, 5 };
29         ed_size slen = ARRAY_SIZE(src);
30         ed_size tlen = ARRAY_SIZE(tgt);
31
32         plan_tests(4);
33
34         ok1(edit_distance(src, slen, tgt, tlen, EDIT_DISTANCE_LCS) == 6);
35         ok1(edit_distance(src, slen, tgt, tlen, EDIT_DISTANCE_LEV) == 4);
36         ok1(edit_distance(src, slen, tgt, tlen, EDIT_DISTANCE_RDL) == 3);
37         ok1(edit_distance(src, slen, tgt, tlen, EDIT_DISTANCE_DL) == 3);
38
39         return exit_status();
40 }