Skip to content

Commit

Permalink
Fix sort logic (euphony-io#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
DahyeonWoo committed Sep 12, 2022
1 parent 5775a70 commit fb31718
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions euphony/src/main/cpp/core/charset/CharsetAutoSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ HexVector CharsetAutoSelector::select(std::string src) {
HexVector utf16Charset = UTF16Charset().encode(src);
HexVector utf32Charset = UTF32Charset().encode(src);

HexVector results[] = {defaultCharset, asciiCharset, utf8Charset, utf16Charset, utf32Charset};
HexVector results[] = {defaultCharset, asciiCharset, utf8Charset, utf16Charset, utf32Charset};

std::sort(results, results+5);
std::sort(results, results+5, [](HexVector& left, HexVector& right) {
return left.getSize() < right.getSize();
});

return results[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ TEST_P(CharsetAutoSelectorTestFixture, SelectTest) {
HexVector utf16Result = utf16Charset->encode(source);
HexVector utf32Result = utf32Charset->encode(source);

HexVector results[] = {asciiResult, defaultResult, utf8Result, utf16Result, utf32Result};

std::sort(results, results+5);
HexVector results[] = {asciiResult, defaultResult, utf8Result, utf16Result, utf32Result};

std::sort(results, results+5, [](HexVector& left, HexVector& right) {
return left.getSize() < right.getSize();
});

HexVector actualResult = results[0];

EXPECT_EQ(actualResult.toString(), expectedResult);
Expand Down

0 comments on commit fb31718

Please sign in to comment.