mirror of
https://github.com/NixOS/nix.git
synced 2025-11-27 04:30:59 +01:00
progress-bar: use dynamic size units
This commit is contained in:
parent
da637a05da
commit
0c53c88367
4 changed files with 205 additions and 14 deletions
|
|
@ -146,6 +146,59 @@ TEST(string2Int, trivialConversions)
|
|||
ASSERT_EQ(string2Int<int>("-100"), -100);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* getSizeUnit
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(getSizeUnit, misc)
|
||||
{
|
||||
ASSERT_EQ(getSizeUnit(0), SizeUnit::Base);
|
||||
ASSERT_EQ(getSizeUnit(100), SizeUnit::Base);
|
||||
ASSERT_EQ(getSizeUnit(100), SizeUnit::Base);
|
||||
ASSERT_EQ(getSizeUnit(972), SizeUnit::Base);
|
||||
ASSERT_EQ(getSizeUnit(973), SizeUnit::Base); // FIXME: should round down
|
||||
ASSERT_EQ(getSizeUnit(1024), SizeUnit::Base);
|
||||
ASSERT_EQ(getSizeUnit(-1024), SizeUnit::Base);
|
||||
ASSERT_EQ(getSizeUnit(1024 * 1024), SizeUnit::Kilo);
|
||||
ASSERT_EQ(getSizeUnit(1100 * 1024), SizeUnit::Mega);
|
||||
ASSERT_EQ(getSizeUnit(2ULL * 1024 * 1024 * 1024), SizeUnit::Giga);
|
||||
ASSERT_EQ(getSizeUnit(2100ULL * 1024 * 1024 * 1024), SizeUnit::Tera);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* getCommonSizeUnit
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(getCommonSizeUnit, misc)
|
||||
{
|
||||
ASSERT_EQ(getCommonSizeUnit({0}), SizeUnit::Base);
|
||||
ASSERT_EQ(getCommonSizeUnit({0, 100}), SizeUnit::Base);
|
||||
ASSERT_EQ(getCommonSizeUnit({100, 0}), SizeUnit::Base);
|
||||
ASSERT_EQ(getCommonSizeUnit({100, 1024 * 1024}), std::nullopt);
|
||||
ASSERT_EQ(getCommonSizeUnit({1024 * 1024, 100}), std::nullopt);
|
||||
ASSERT_EQ(getCommonSizeUnit({1024 * 1024, 1024 * 1024}), SizeUnit::Kilo);
|
||||
ASSERT_EQ(getCommonSizeUnit({2100ULL * 1024 * 1024 * 1024, 2100ULL * 1024 * 1024 * 1024}), SizeUnit::Tera);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* renderSizeWithoutUnit
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(renderSizeWithoutUnit, misc)
|
||||
{
|
||||
ASSERT_EQ(renderSizeWithoutUnit(0, SizeUnit::Base, true), " 0.0");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(100, SizeUnit::Base, true), " 0.1");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(100, SizeUnit::Base), "0.1");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(972, SizeUnit::Base, true), " 0.9");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(973, SizeUnit::Base, true), " 1.0"); // FIXME: should round down
|
||||
ASSERT_EQ(renderSizeWithoutUnit(1024, SizeUnit::Base, true), " 1.0");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(-1024, SizeUnit::Base, true), " -1.0");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(1024 * 1024, SizeUnit::Kilo, true), "1024.0");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(1100 * 1024, SizeUnit::Mega, true), " 1.1");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(2ULL * 1024 * 1024 * 1024, SizeUnit::Giga, true), " 2.0");
|
||||
ASSERT_EQ(renderSizeWithoutUnit(2100ULL * 1024 * 1024 * 1024, SizeUnit::Tera, true), " 2.1");
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* renderSize
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue