File: count_utf16be.cpp

package info (click to toggle)
simdutf 8.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,524 kB
  • sloc: cpp: 64,498; ansic: 15,347; python: 3,592; sh: 366; makefile: 12
file content (64 lines) | stat: -rw-r--r-- 1,624 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "simdutf.h"

#include <array>
#include <vector>

#include <tests/helpers/fixed_string.h>
#include <tests/helpers/random_int.h>
#include <tests/helpers/random_utf16.h>
#include <tests/helpers/test.h>

namespace {
std::array<size_t, 7> input_size{7, 16, 12, 64, 67, 128, 256};

} // namespace

TEST_LOOP(count_just_one_word) {
  simdutf::tests::helpers::random_utf16 random(seed, 1, 0);

  for (size_t size : input_size) {
    const auto g = random.generate_counted_be(size);
    const auto &utf16 = g.first;
    const auto utf16_count = g.second;

    const size_t count = implementation.count_utf16be(utf16.data(), size);
    ASSERT_EQUAL(count, utf16_count);
  }
}

TEST_LOOP(count_1_or_2_UTF16_words) {
  simdutf::tests::helpers::random_utf16 random(seed, 1, 1);

  for (size_t size : input_size) {
    const auto g = random.generate_counted_be(size);
    const auto &utf16 = g.first;
    const auto utf16_count = g.second;

    const size_t count = implementation.count_utf16be(utf16.data(), size);
    ASSERT_EQUAL(count, utf16_count);
  }
}

TEST_LOOP(count_2_UTF16_words) {
  simdutf::tests::helpers::random_utf16 random(seed, 0, 1);

  for (size_t size : input_size) {
    const auto g = random.generate_counted_be(size);
    const auto &utf16 = g.first;
    const auto utf16_count = g.second;

    const size_t count = implementation.count_utf16be(utf16.data(), size);
    ASSERT_EQUAL(count, utf16_count);
  }
}

#if SIMDUTF_CPLUSPLUS23

TEST(compile_time_count_utf16be) {
  using namespace simdutf::tests::helpers;

  static_assert(simdutf::count_utf16be(u"köttbulle"_utf16be) == 9);
}
#endif

TEST_MAIN