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

Fixes the issue that the Chinese number module does not correctly handle zero. #146

Merged
merged 2 commits into from
Jul 30, 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
31 changes: 31 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@ name: CI
on: [push, pull_request]

jobs:
build_ubuntu_24:
runs-on: ubuntu-latest
container: ubuntu:24.04

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt install -y pkg-config
apt install -y clang
apt install -y cmake extra-cmake-modules gettext libfmt-dev
apt install -y fcitx5 libfcitx5core-dev libfcitx5config-dev libfcitx5utils-dev fcitx5-modules-dev
apt install -y libjson-c-dev
- name: Build
run: |
mkdir -p build
cd build
cmake ../ -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug
make -j
cd ../
mkdir -p src/Engine/build
cd src/Engine/build
cmake ../
make -j
- name: Test
run: |
cd build
ctest --output-on-failure

build_ubuntu_22:
runs-on: ubuntu-latest
container: ubuntu:22.04
Expand Down
6 changes: 5 additions & 1 deletion src/ChineseNumbers/ChineseNumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ std::string ChineseNumbers::Generate(const std::string& intPart,

std::stringstream output;
if (intTrimmed.empty()) {
output << "0";
if (digitCase == ChineseNumbers::ChineseNumberCase::LOWERCASE) {
output << kLowerDigits[0];
} else if (digitCase == ChineseNumbers::ChineseNumberCase::UPPERCASE) {
output << kUpperDigits[0];
}
} else {
size_t intSectionCount = static_cast<size_t>(
ceil(static_cast<double>(intTrimmed.length()) / 4.0));
Expand Down
12 changes: 12 additions & 0 deletions src/ChineseNumbers/ChineseNumbersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
#include "ChineseNumbers.h"
#include "gtest/gtest.h"

TEST(ChineseNumberTest, Test0_lower) {
std::string output = ChineseNumbers::Generate(
"0000", "0", ChineseNumbers::ChineseNumberCase::LOWERCASE);
EXPECT_EQ(output, "〇");
}

TEST(ChineseNumberTest, Test0_uipper) {
std::string output = ChineseNumbers::Generate(
"0000", "0", ChineseNumbers::ChineseNumberCase::UPPERCASE);
EXPECT_EQ(output, "零");
}

TEST(ChineseNumberTest, Test1) {
std::string output = ChineseNumbers::Generate(
"0001", "0", ChineseNumbers::ChineseNumberCase::LOWERCASE);
Expand Down