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