xref: /aosp_15_r20/external/libtextclassifier/native/utils/tokenfree/byte_encoder_test.cc (revision 993b0882672172b81d12fad7a7ac0c3e5c824a12)
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "utils/tokenfree/byte_encoder.h"
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "utils/base/integral_types.h"
23 #include "utils/container/sorted-strings-table.h"
24 #include "gmock/gmock.h"
25 #include "gtest/gtest.h"
26 
27 namespace libtextclassifier3 {
28 namespace {
29 
30 using testing::ElementsAre;
31 
TEST(ByteEncoderTest,SimpleTokenization)32 TEST(ByteEncoderTest, SimpleTokenization) {
33   const ByteEncoder encoder;
34   {
35     std::vector<int64_t> encoded_text;
36     EXPECT_TRUE(encoder.Encode("hellothere", &encoded_text));
37     EXPECT_THAT(encoded_text,
38                 ElementsAre(104, 101, 108, 108, 111, 116, 104, 101, 114, 101));
39   }
40 }
41 
TEST(ByteEncoderTest,SimpleTokenization2)42 TEST(ByteEncoderTest, SimpleTokenization2) {
43   const ByteEncoder encoder;
44   {
45     std::vector<int64_t> encoded_text;
46     EXPECT_TRUE(encoder.Encode("Hello", &encoded_text));
47     EXPECT_THAT(encoded_text, ElementsAre(72, 101, 108, 108, 111));
48   }
49 }
50 }  // namespace
51 }  // namespace libtextclassifier3
52