File indexing completed on 2024-05-19 05:42:29
0001 // ct_lvtshr_fuzzyutil.t.cpp -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #include <ct_lvtshr_fuzzyutil.h> 0021 0022 #include <array> 0023 #include <string> 0024 #include <tuple> 0025 #include <utility> 0026 0027 #include <catch2-local-includes.h> 0028 0029 using Codethink::lvtshr::FuzzyUtil; 0030 0031 TEST_CASE("Fuzzy util") 0032 { 0033 using TestCase = std::tuple<std::string, std::string, size_t>; 0034 0035 static const std::array<TestCase, 11> tests = {TestCase{"", "", 0}, 0036 TestCase{"a", "", 1}, 0037 TestCase{"", "a", 1}, 0038 TestCase{"kitten", "sitting", 3}, 0039 TestCase{"12", "", 2}, 0040 TestCase{"akitten", "asitting", 3}, 0041 TestCase{"akitten", "sitting", 4}, 0042 TestCase{"kitten", "asitting", 4}, 0043 TestCase{"pkg", "package", 4}, 0044 TestCase{"book", "back", 2}, 0045 TestCase{"apple", "jklfdas", 7}}; 0046 0047 for (const auto& test : tests) { 0048 const auto& lhs = std::get<0>(test); 0049 const auto& rhs = std::get<1>(test); 0050 const auto expDist = std::get<2>(test); 0051 const auto dist = FuzzyUtil::levensteinDistance(lhs, rhs); 0052 CHECK(expDist == dist); 0053 } 0054 }