1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-29 01:33:46 +00:00

Add unit test for cli programs

This commit is contained in:
King_DuckZ 2016-04-21 00:22:00 +02:00
parent e3e704c50f
commit abde34e240
4 changed files with 111 additions and 1 deletions

View file

@ -114,6 +114,7 @@ add_subdirectory(src/navigate)
#Tests
add_subdirectory(test/gtest)
add_subdirectory(test/unit)
add_subdirectory(test/unit_cli)
target_link_libraries(${PROJECT_NAME}
INTERFACE ${PostgreSQL_LIBRARIES}

View file

@ -19,7 +19,15 @@
#define id88738025C6B24BDEB604A5AE3C36EE8D
#include "helpers/compatibility.h"
#include "stddef.h"
#if defined(__cplusplus)
# include <cstddef>
#else
# include <stddef.h>
#endif
#if defined(__cplusplus)
extern "C" {
#endif
int damerau_levenshtein (
const char* parSource,
@ -41,4 +49,8 @@ int damerau_levenshtein_with_size (
int parSwapCost
) a_pure;
#if defined(__cplusplus)
}
#endif
#endif

View file

@ -0,0 +1,25 @@
project(${bare_name}-test_cli CXX C)
add_executable(${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/src/main/damerau_levenshtein.c
${CMAKE_SOURCE_DIR}/src/main/utf8_ops.c
test_damerau_levenshtein.cpp
)
target_include_directories(${PROJECT_NAME}
PRIVATE ${CMAKE_SOURCE_DIR}/src
PRIVATE ${CMAKE_SOURCE_DIR}/lib/pbl/pbl/src/src
)
target_include_directories(${PROJECT_NAME} SYSTEM
PRIVATE ../gtest/include
)
target_link_libraries(${PROJECT_NAME}
PRIVATE ${bare_name}-if
PRIVATE ${bare_name}-common
PRIVATE ${bare_name}-machinery
PRIVATE gtest
PRIVATE gtest_main
PRIVATE pbl
)

View file

@ -0,0 +1,72 @@
/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" 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 3 of the License, or
* (at your option) any later version.
*
* "dindexer" 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 "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "main/damerau_levenshtein.h"
TEST(cli_main, damerau_levenshtein) {
{
const char source1[] = u8"navigte";
const char source2[] = u8"navigäte";
const char source3[] = u8"navigbte";
const char source4[] = u8"narigate";
const char source5[] = u8"navigate";
const char target[] = u8"navigate";
EXPECT_EQ(1, damerau_levenshtein(source1, target, 1, 1, 1, 1));
EXPECT_EQ(1, damerau_levenshtein(source2, target, 1, 1, 1, 1));
EXPECT_EQ(1, damerau_levenshtein(source3, target, 1, 1, 1, 1));
EXPECT_EQ(1, damerau_levenshtein(source4, target, 1, 1, 1, 1));
EXPECT_EQ(0, damerau_levenshtein(source5, target, 1, 1, 1, 1));
}
{
const char source[] = u8"navigaäte";
const char target[] = u8"navigate";
EXPECT_EQ(1, damerau_levenshtein(source, target, 1, 1, 1, 1));
}
{
const char source1[] = u8"navigaäbcde";
const char source2[] = u8"navigaabcde";
const char target[] = u8"navigate";
EXPECT_EQ(4, damerau_levenshtein(source1, target, 1, 1, 1, 1));
EXPECT_EQ(4, damerau_levenshtein(source2, target, 1, 1, 1, 1));
}
{
const char source[] = u8"";
const char target[] = u8"navigate";
EXPECT_EQ(8, damerau_levenshtein(source, target, 1, 1, 1, 1));
EXPECT_EQ(8, damerau_levenshtein(target, source, 1, 1, 1, 1));
}
{
const char source[] = u8"ありがとうございました";
const char target[] = u8"りがとうございました";
EXPECT_EQ(1, damerau_levenshtein(source, target, 1, 1, 1, 1));
}
{
const char source1[] = u8"Kanji 金 reads かね.";
const char source2[] = u8"Kanji ⿔ reads かめ.";
const char target[] = u8"Kanji 亀 reads かめ.";
EXPECT_EQ(2, damerau_levenshtein(source1, target, 1, 1, 1, 1));
EXPECT_EQ(1, damerau_levenshtein(source2, target, 1, 1, 1, 1));
}
{
const char source[] = u8"\"槪\" and \"🚮\" have a long utf8 sequence.";
const char target1[] = u8"\"槪\" or \"🚮\" have a long utf8 sequence.";
const char target2[] = u8"\"槪\" or \"🚻\" have a long utf8 sequence.";
EXPECT_EQ(3, damerau_levenshtein(source, target1, 1, 1, 1, 1));
EXPECT_EQ(4, damerau_levenshtein(source, target2, 1, 1, 1, 1));
}
}