# include # include # include # include # include "levenshtein_distance.h" int main ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: levenshtein_distance_test() tests levenshtein_distance(). Licensing: This code is distributed under the MIT license. Modified: 10 September 2022 Author: John Burkardt */ { int d1; int d2; int m; int n; char *s1 = "water"; char *s2 = "kitten"; char *s3 = "saturday"; char *s4 = "pheromones"; char *t1 = "wine"; char *t2 = "sitting"; char *t3 = "sunday"; char *t4 = "photographer"; timestamp ( ); printf ( "\n" ); printf ( "levenshtein_distance_test():\n" ); printf ( " C version\n" ); printf ( " levenshtein_distance() computes the Levenshtein distance between two strings.\n" ); m = strlen ( s1 ); n = strlen ( t1 ); d1 = levenshtein_distance ( m, s1, n, t1 ); d2 = 3; printf ( "\n" ); printf ( " S = '%s'\n", s1 ); printf ( " T = '%s'\n", t1 ); printf ( " Computed distance = %d\n", d1 ); printf ( " Correct distance = %d\n", d2 ); m = strlen ( s2 ); n = strlen ( t2 ); d1 = levenshtein_distance ( m, s2, n, t2 ); d2 = 3; printf ( "\n" ); printf ( " S = '%s'\n", s2 ); printf ( " T = '%s'\n", t2 ); printf ( " Computed distance = %d\n", d1 ); printf ( " Correct distance = %d\n", d2 ); m = strlen ( s3 ); n = strlen ( t3 ); d1 = levenshtein_distance ( m, s3, n, t3 ); d2 = 3; printf ( "\n" ); printf ( " S = '%s'\n", s3 ); printf ( " T = '%s'\n", t3 ); printf ( " Computed distance = %d\n", d1 ); printf ( " Correct distance = %d\n", d2 ); m = strlen ( s4 ); n = strlen ( t4 ); d1 = levenshtein_distance ( m, s4, n, t4 ); d2 = 8; printf ( "\n" ); printf ( " S = '%s'\n", s4 ); printf ( " T = '%s'\n", t4 ); printf ( " Computed distance = %d\n", d1 ); printf ( " Correct distance = %d\n", d2 ); /* Terminate. */ printf ( "\n" ); printf ( "levenshtein_distance_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }