Add wxBitmapBundle::GetConsensusSizeFor(double) and test it

Add an overload of the existing function which can be easily tested in
the unit tests and add a trivial new test for it.
This commit is contained in:
Vadim Zeitlin
2022-06-05 00:16:58 +01:00
parent 34fa234f48
commit 907e4ea862
3 changed files with 45 additions and 2 deletions

View File

@@ -460,3 +460,34 @@ TEST_CASE("BitmapBundle::Scale", "[bmpbundle][scale]")
}
#endif // ports with scaled bitmaps support
TEST_CASE("BitmapBundle::GetConsensusSize", "[bmpbundle]")
{
// Just a trivial helper to make writing the tests below simpler.
struct Bundles
{
wxVector<wxBitmapBundle> vec;
void Add(int size)
{
vec.push_back(wxBitmapBundle::FromBitmap(wxSize(size, size)));
}
int GetConsensusSize(double scale) const
{
return wxBitmapBundle::GetConsensusSizeFor(scale, vec, wxSize()).y;
}
} bundles;
// When there is a tie, a larger size is chosen by default.
bundles.Add(16);
bundles.Add(24);
CHECK( bundles.GetConsensusSize(2) == 48 );
// Breaking the tie results in the smaller size winning now.
bundles.Add(16);
CHECK( bundles.GetConsensusSize(2) == 32 );
// Integer scaling factors should be preferred.
CHECK( bundles.GetConsensusSize(1.5) == 16 );
}