Skip to content

Commit

Permalink
add tests for maxinum and mininum for int32_5
Browse files Browse the repository at this point in the history
  • Loading branch information
jingkaimori committed Oct 30, 2023
1 parent 423aa95 commit d285b89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Kernel/Types/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ static string chars_han[10]= {
"<unspecified>", "", "", "", "", "", "", "", "", ""};

string
hanzi_sub (int nr, bool leading_zero) {
hanzi_sub (int16_t nr, bool leading_zero) {
short thousand= (nr % 10000) / 1000, hundred= (nr % 1000) / 100,
ten= (nr % 100) / 10, one= nr % 10;
short cases= (leading_zero << 4) | ((thousand == 0) << 3) |
Expand Down Expand Up @@ -660,10 +660,12 @@ hanzi_sub (int nr, bool leading_zero) {
return "<unspecified>" * as_string (cases);
}
}

string
hanzi_nr (int nr) {
if (nr < 0) return "" * hanzi_nr (-nr);
hanzi_nr (int32_t nr) {
if (nr == 0) return "";
if (nr == 0x80000000) return "负二十一亿四千七百四十八万三千六百四十八";
if (nr < 0) return "" * hanzi_nr (-nr);
if (nr >= 100000000) {
return hanzi_sub (nr / 100000000, false) * "亿" *
hanzi_sub ((nr / 10000) % 10000, true) * "" *
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Types/analyze.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ string fnsymbol_nr (int nr);
* @param nr The integer to be converted to a Chinese numeral.
* @return A string representing the Chinese numeral.
*/
string hanzi_nr (int nr);
string hanzi_nr (int32_t nr);

/**
* @brief Converts an integer to a hexadecimal string.
Expand Down
2 changes: 2 additions & 0 deletions tests/Kernel/Types/analyze_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,6 @@ TEST_CASE ("hanzi_nr") {
string_eq (hanzi_nr (10001), "一万零一");
string_eq (hanzi_nr (153457), "十五万三千四百五十七");
string_eq (hanzi_nr (300153457), "三亿零一十五万三千四百五十七");
string_eq (hanzi_nr (0x7FFFFFFF), "二十一亿四千七百四十八万三千六百四十七");
string_eq (hanzi_nr (0x80000000), "负二十一亿四千七百四十八万三千六百四十八");
}

0 comments on commit d285b89

Please sign in to comment.