Skip to content

Commit

Permalink
Small refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvov1 committed Oct 21, 2024
1 parent 358de84 commit 1a185b1
Showing 1 changed file with 47 additions and 35 deletions.
82 changes: 47 additions & 35 deletions test/operations/display/unsigned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,42 @@ TEST(Unsigned_Display, Zero) {

std::array<char, 10> askii{};
std::array<wchar_t, 10> utf{};
auto size = m.getString<10>(askii.data(), 10, false);
m.getString<10>(askii.data(), 10, false);
EXPECT_EQ(std::string_view(askii.data()), "0"sv);

askii = {};
size = m.getString<2>(askii.data(), 10, true);
m.getString<2>(askii.data(), 10, true);
EXPECT_EQ(std::string_view(askii.data()), "0b0"sv);

askii = {};
size = m.getString<8>(askii.data(), 10, true);
m.getString<8>(askii.data(), 10, true);
EXPECT_EQ(std::string_view(askii.data()), "0o0"sv);

askii = {};
size = m.getString<10>(askii.data(), 10, true);
m.getString<10>(askii.data(), 10, true);
EXPECT_EQ(std::string_view(askii.data()), "0"sv);

askii = {};
size = m.getString<16>(askii.data(), 10, true);
m.getString<16>(askii.data(), 10, true);
EXPECT_EQ(std::string_view(askii.data()), "0x0"sv);

size = m.getString<10>(utf.data(), 10);
m.getString<10>(utf.data(), 10);
EXPECT_EQ(std::wstring_view(utf.data()), L"0"sv);

utf = {};
size = m.getString<2>(utf.data(), 10, true);
m.getString<2>(utf.data(), 10, true);
EXPECT_EQ(std::wstring_view(utf.data()), L"0b0"sv);

utf = {};
size = m.getString<8>(utf.data(), 10, true);
m.getString<8>(utf.data(), 10, true);
EXPECT_EQ(std::wstring_view(utf.data()), L"0o0"sv);

utf = {};
size = m.getString<10>(utf.data(), 10, true);
m.getString<10>(utf.data(), 10, true);
EXPECT_EQ(std::wstring_view(utf.data()), L"0"sv);

utf = {};
size = m.getString<16>(utf.data(), 10, true);
m.getString<16>(utf.data(), 10, true);
EXPECT_EQ(std::wstring_view(utf.data()), L"0x0"sv);
}
}
Expand All @@ -70,7 +70,8 @@ TEST(Unsigned_Display, DecimalStreams) {
const auto value = Generation::getRandomWithBits(blocksNumber * 32 - 32);
const Aeu<blocksNumber * 32> aeu = value;

std::stringstream ss, ss2; ss << std::dec << std::noshowbase << value;
std::stringstream ss, ss2;
ss << std::dec << std::noshowbase << value;
ss2 << std::dec << std::noshowbase << aeu;
EXPECT_EQ(ss2.str(), ss.str());
}
Expand All @@ -79,8 +80,11 @@ TEST(Unsigned_Display, DecimalStreams) {
const auto value = Generation::getRandomWithBits(blocksNumber * 32 - 32);
const Aeu<blocksNumber * 32> aeu = value;

std::stringstream ss; ss << std::dec << std::noshowbase << value;
std::wstringstream ss2; ss2 << std::dec << std::noshowbase << aeu;
std::stringstream ss;
ss << std::dec << std::noshowbase << value;
std::wstringstream ss2;
ss2 << std::dec << std::noshowbase << aeu;

const auto& ref = ss.str();
std::wstring wstring (ref.begin(), ref.end());
EXPECT_EQ(ss2.str(), wstring);
Expand All @@ -94,7 +98,8 @@ TEST(Unsigned_Display, OctalStreams) {
const auto value = Generation::getRandomWithBits(blocksNumber * 32 - 32);
const Aeu<blocksNumber * 32> aeu = value;

std::stringstream ss, ss2; ss << "0o" << std::oct << std::noshowbase << value;
std::stringstream ss, ss2;
ss << "0o" << std::oct << std::noshowbase << value;
ss2 << "0o" << std::oct << std::noshowbase << aeu;
EXPECT_EQ(ss2.str(), ss.str());
}
Expand All @@ -103,8 +108,11 @@ TEST(Unsigned_Display, OctalStreams) {
const auto value = Generation::getRandomWithBits(blocksNumber * 32 - 32);
const Aeu<blocksNumber * 32> aeu = value;

std::stringstream ss; ss << "0o" << std::oct << std::noshowbase << value;
std::wstringstream ss2; ss2 << "0o" << std::oct << std::noshowbase << aeu;
std::stringstream ss;
ss << "0o" << std::oct << std::noshowbase << value;
std::wstringstream ss2;
ss2 << "0o" << std::oct << std::noshowbase << aeu;

const auto& ref = ss.str();
std::wstring wstring (ref.begin(), ref.end());
EXPECT_EQ(ss2.str(), wstring);
Expand All @@ -118,7 +126,8 @@ TEST(Unsigned_Display, HexadecimalStreams) {
const auto value = Generation::getRandomWithBits(blocksNumber * 32 - 32);
const Aeu<blocksNumber * 32> aeu = value;

std::stringstream ss, ss2; ss << "0x" << std::hex << std::noshowbase << value;
std::stringstream ss, ss2;
ss << "0x" << std::hex << std::noshowbase << value;
ss2 << "0x" << std::hex << std::noshowbase << aeu;
EXPECT_EQ(ss2.str(), ss.str());
}
Expand All @@ -127,8 +136,11 @@ TEST(Unsigned_Display, HexadecimalStreams) {
const auto value = Generation::getRandomWithBits(blocksNumber * 32 - 32);
const Aeu<blocksNumber * 32> aeu = value;

std::stringstream ss; ss << "0x" << std::hex << std::noshowbase << value;
std::wstringstream ss2; ss2 << "0x" << std::hex << std::noshowbase << aeu;
std::stringstream ss;
ss << "0x" << std::hex << std::noshowbase << value;
std::wstringstream ss2;
ss2 << "0x" << std::hex << std::noshowbase << aeu;

const auto& ref = ss.str();
std::wstring wstring (ref.begin(), ref.end());
EXPECT_EQ(ss2.str(), wstring);
Expand All @@ -155,22 +167,22 @@ TEST(Unsigned_Display, FormatAskii) {
switch(i % 5) {
case 0: { /* Octal */
ss << std::oct << std::noshowbase << value;
const auto size = aeu.getString<8>(askii.data(), askii.size(), false);
aeu.getString<8>(askii.data(), askii.size(), false);
break;
}
case 1: { /* Hexadecimal, lowercase */
ss << std::hex << std::noshowbase << std::nouppercase << value;
const auto size = aeu.getString<16>(askii.data(), askii.size(), false, false);
aeu.getString<16>(askii.data(), askii.size(), false, false);
break;
}
case 2: { /* Hexadecimal, uppercase */
ss << std::hex << std::noshowbase << std::uppercase << value;
const auto size = aeu.getString<16>(askii.data(), askii.size(), false, true);
aeu.getString<16>(askii.data(), askii.size(), false, true);
break;
}
case 3: { /* Decimal */
ss << std::dec << std::noshowbase << value;
const auto size = aeu.getString<10>(askii.data(), askii.size(), false);
aeu.getString<10>(askii.data(), askii.size(), false);
break;
}
default: { /* Binary */
Expand Down Expand Up @@ -208,22 +220,22 @@ TEST(Unsigned_Display, FormatUtf) {
switch (i % 5) {
case 0: { /* Octal */
ss << std::oct << std::noshowbase << value;
const auto size = aeu.getString<8>(utf.data(), utf.size(), false);
aeu.getString<8>(utf.data(), utf.size(), false);
break;
}
case 1: { /* Hexadecimal, lowercase */
ss << std::hex << std::noshowbase << std::nouppercase << value;
const auto size = aeu.getString<16>(utf.data(), utf.size(), false, false);
aeu.getString<16>(utf.data(), utf.size(), false, false);
break;
}
case 2: { /* Hexadecimal, uppercase */
ss << std::hex << std::noshowbase << std::uppercase << value;
const auto size = aeu.getString<16>(utf.data(), utf.size(), false, true);
aeu.getString<16>(utf.data(), utf.size(), false, true);
break;
}
case 3: { /* Decimal */
ss << std::dec << std::noshowbase << value;
const auto size = aeu.getString<10>(utf.data(), utf.size(), false);
aeu.getString<10>(utf.data(), utf.size(), false);
break;
}
default: { /* Binary */
Expand Down Expand Up @@ -292,25 +304,25 @@ TEST(Unsigned_Display, ShowBaseAskii) {
}
case 4: { /* C-style ASKII Octal */
ss << "0o" << std::oct << std::noshowbase << value;
const auto size = aeu.getString<8>(askii.data(), askii.size(), true);
aeu.getString<8>(askii.data(), askii.size(), true);
EXPECT_EQ(std::string_view(askii.data()), ss.str());
break;
}
case 5: { /* C-style ASKII Hexadecimal, lowercase */
ss << "0x" << std::hex << std::noshowbase << std::nouppercase << value;
const auto size = aeu.getString<16>(askii.data(), askii.size(), true, false);
aeu.getString<16>(askii.data(), askii.size(), true, false);
EXPECT_EQ(std::string_view(askii.data()), ss.str());
break;
}
case 6: { /* C-style ASKII Hexadecimal, uppercase */
ss << "0x" << std::hex << std::noshowbase << std::nouppercase << value;
const auto size = aeu.getString<16>(askii.data(), askii.size(), true, false);
aeu.getString<16>(askii.data(), askii.size(), true, false);
EXPECT_EQ(std::string_view(askii.data()), ss.str());
break;
}
case 7: { /* C-style ASKII Decimal */
ss << std::dec << std::noshowbase << value;
const auto size = aeu.getString<10>(askii.data(), askii.size(), true);
aeu.getString<10>(askii.data(), askii.size(), true);
EXPECT_EQ(std::string_view(askii.data()), ss.str());
break;
}
Expand Down Expand Up @@ -386,31 +398,31 @@ TEST(Unsigned_Display, ShowBaseUtf) {
}
case 4: { /* C-style ASKII Octal */
ss << "0o" << std::oct << std::noshowbase << value;
const auto size = aeu.getString<8>(utf.data(), utf.size(), true);
aeu.getString<8>(utf.data(), utf.size(), true);
const auto &ref = ss.str();
const std::wstring comparative(ref.begin(), ref.end());
EXPECT_EQ(std::wstring_view(utf.data()), comparative);
break;
}
case 5: { /* C-style ASKII Hexadecimal, lowercase */
ss << "0x" << std::hex << std::noshowbase << std::nouppercase << value;
const auto size = aeu.getString<16>(utf.data(), utf.size(), true, false);
aeu.getString<16>(utf.data(), utf.size(), true, false);
const auto &ref = ss.str();
const std::wstring comparative(ref.begin(), ref.end());
EXPECT_EQ(std::wstring_view(utf.data()), comparative);
break;
}
case 6: { /* C-style ASKII Hexadecimal, uppercase */
ss << "0x" << std::hex << std::noshowbase << std::nouppercase << value;
const auto size = aeu.getString<16>(utf.data(), utf.size(), true, false);
aeu.getString<16>(utf.data(), utf.size(), true, false);
const auto &ref = ss.str();
const std::wstring comparative(ref.begin(), ref.end());
EXPECT_EQ(std::wstring_view(utf.data()), comparative);
break;
}
case 7: { /* C-style ASKII Decimal */
ss << std::dec << std::noshowbase << value;
const auto size = aeu.getString<10>(utf.data(), utf.size(), true);
aeu.getString<10>(utf.data(), utf.size(), true);
const auto &ref = ss.str();
const std::wstring comparative(ref.begin(), ref.end());
EXPECT_EQ(std::wstring_view(utf.data()), comparative);
Expand Down

0 comments on commit 1a185b1

Please sign in to comment.