1 /* EasyTAG - tag editor for audio files
2  * Copyright (C) 2014 David King <amigadave@amigadave.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "dlm.h"
20 
21 static void
dlm_dlm(void)22 dlm_dlm (void)
23 {
24     gsize i;
25 
26     static const struct
27     {
28         const gchar *str1;
29         const gchar *str2;
30         const gint metric;
31     } strings[] =
32     {
33         { "foo", "foo", 1000 },
34         { "foo", "bar", 0 },
35         { "bar", "baz", 667 },
36         { "bar", "bra", 667 },
37         { "bar", "ba", 600 },
38         { "ba", "bar", 600 },
39         { "foobarbaz", "foobarbaz", 1000 },
40         { "foobarbaz", "foobazbar", 778 },
41         { "foobarbaz", "zabraboof", 223 },
42         { "foobarbaz", "iiiiiiiii", 0 },
43         { "1234567890", "abcdefghij", 0 },
44         { "", "", -1 },
45         { "foo", "", -1 },
46         { "", "foo", -1 },
47     };
48 
49     for (i = 0; i < G_N_ELEMENTS (strings); i++)
50     {
51         gint metric;
52 
53         metric = dlm (strings[i].str1, strings[i].str2);
54         g_assert_cmpint (strings[i].metric, ==, metric);
55     }
56 }
57 
58 static void
dlm_perf_dlm(void)59 dlm_perf_dlm (void)
60 {
61     gsize i;
62     const gsize PERF_ITERATIONS = 500000;
63     gdouble time;
64 
65     g_test_timer_start ();
66 
67     for (i = 0; i < PERF_ITERATIONS; i++)
68     {
69         g_assert_cmpint (dlm ("foobarbaz", "zabraboof"), ==, 223);
70     }
71 
72     time = g_test_timer_elapsed ();
73 
74     g_test_minimized_result (time, "%6.1f seconds", time);
75 }
76 
77 int
main(int argc,char ** argv)78 main (int argc, char** argv)
79 {
80     g_test_init (&argc, &argv, NULL);
81 
82     g_test_add_func ("/dlm/dlm", dlm_dlm);
83 
84     if (g_test_perf ())
85     {
86         g_test_add_func ("/dlm/perf/dlm", dlm_perf_dlm);
87     }
88 
89     return g_test_run ();
90 }
91