Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base64 test #3

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:

# Run unit tests
RESOURCES_PATH=test/resources build/sentencepiece_test
build/tiktoken_test
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ if(TOKENIZERS_BUILD_TEST)
sentencepiece_test PUBLIC third-party/sentencepiece/src
third-party/sentencepiece include GTEST_INCLUDE_PATH)
target_link_libraries(sentencepiece_test PUBLIC tokenizers gtest_main)

# tiktoken tests
add_executable(tiktoken_test test/test_base64.cpp)
target_include_directories(tiktoken_test PUBLIC include GTEST_INCLUDE_PATH)
target_link_libraries(tiktoken_test PUBLIC gtest_main)
endif()
35 changes: 35 additions & 0 deletions test/test_base64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "base64.h"
#include "gtest/gtest.h"

namespace tokenizers {

TEST(Base64Test, TestDecodeSmoke) {
std::string text = "bGxhbWE=";
auto result = base64::decode(text);
EXPECT_TRUE(result.ok());
EXPECT_EQ(result.get(), "llama");
}

TEST(Base64Test, TestDecodeEmptyStringReturnsError) {
std::string text = "";
auto result = base64::decode(text);
EXPECT_FALSE(result.ok());
EXPECT_EQ(result.error(), Error::Base64DecodeFailure);
}

TEST(Base64Test, TestInvalidStringDecodeReturnsError) {
std::string text = "llama";
auto result = base64::decode(text);
EXPECT_FALSE(result.ok());
EXPECT_EQ(result.error(), Error::Base64DecodeFailure);
}

} // namespace tokenizers