File: tests-common.cpp

package info (click to toggle)
rapidfuzz-cpp 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,480 kB
  • sloc: cpp: 30,893; python: 63; makefile: 26; sh: 8
file content (42 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download
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
#include "rapidfuzz/details/Range.hpp"

#if CATCH2_VERSION == 2
#    include <catch2/catch.hpp>
#else
#    include <catch2/catch_approx.hpp>
#    include <catch2/catch_test_macros.hpp>
#endif

#include <rapidfuzz/details/common.hpp>

TEST_CASE("remove affix")
{
    std::string s1 = "aabbbbaaaa";
    std::string s2 = "aaabbbbaaaaa";

    {
        auto s1_ = rapidfuzz::detail::make_range(s1);
        auto s2_ = rapidfuzz::detail::make_range(s2);
        REQUIRE(rapidfuzz::detail::remove_common_prefix(s1_, s2_) == 2);
        REQUIRE(s1_ == rapidfuzz::detail::make_range("bbbbaaaa"));
        REQUIRE(s2_ == rapidfuzz::detail::make_range("abbbbaaaaa"));
    }

    {
        auto s1_ = rapidfuzz::detail::make_range(s1);
        auto s2_ = rapidfuzz::detail::make_range(s2);
        REQUIRE(rapidfuzz::detail::remove_common_suffix(s1_, s2_) == 4);
        REQUIRE(s1_ == rapidfuzz::detail::make_range("aabbbb"));
        REQUIRE(s2_ == rapidfuzz::detail::make_range("aaabbbba"));
    }

    {
        auto s1_ = rapidfuzz::detail::make_range(s1);
        auto s2_ = rapidfuzz::detail::make_range(s2);
        auto affix = rapidfuzz::detail::remove_common_affix(s1_, s2_);
        REQUIRE(affix.prefix_len == 2);
        REQUIRE(affix.suffix_len == 4);
        REQUIRE(s1_ == rapidfuzz::detail::make_range("bbbb"));
        REQUIRE(s2_ == rapidfuzz::detail::make_range("abbbba"));
    }
}