mirror of https://github.com/polybar/polybar.git
tests: Convert math test to gtest
This commit is contained in:
parent
067aac1ac7
commit
f983bb63bb
|
@ -1,78 +1,76 @@
|
||||||
#include "common/test.hpp"
|
#include "common/test.hpp"
|
||||||
#include "utils/math.hpp"
|
#include "utils/math.hpp"
|
||||||
|
|
||||||
int main() {
|
|
||||||
using namespace polybar;
|
using namespace polybar;
|
||||||
|
|
||||||
"min"_test = [] {
|
TEST(Math, min) {
|
||||||
expect(math_util::min<int>(2, 5) == 2);
|
EXPECT_EQ(2, math_util::min<int>(2, 5));
|
||||||
expect(math_util::min<int>(-8, -50) == -50);
|
EXPECT_EQ(-50, math_util::min<int>(-8, -50));
|
||||||
expect(math_util::min<unsigned char>(0, -5) == 0);
|
EXPECT_EQ(0, math_util::min<unsigned char>(0, -5));
|
||||||
};
|
}
|
||||||
|
|
||||||
"min"_test = [] {
|
TEST(Math, max) {
|
||||||
expect(math_util::max<int>(2, 5) == 5);
|
EXPECT_EQ(5, math_util::max<int>(2, 5));
|
||||||
expect(math_util::max<int>(-8, -50) == -8);
|
EXPECT_EQ(-8, math_util::max<int>(-8, -50));
|
||||||
expect(math_util::max<unsigned char>(0, (1 << 8) - 5));
|
EXPECT_EQ(251, math_util::max<unsigned char>(0, (1 << 8) - 5));
|
||||||
};
|
}
|
||||||
|
|
||||||
"cap"_test = [] {
|
TEST(Math, cap) {
|
||||||
expect(math_util::cap<int>(8, 0, 10) == 8);
|
EXPECT_EQ(8, math_util::cap<int>(8, 0, 10));
|
||||||
expect(math_util::cap<int>(-8, 0, 10) == 0);
|
EXPECT_EQ(0, math_util::cap<int>(-8, 0, 10));
|
||||||
expect(math_util::cap<int>(15, 0, 10) == 10);
|
EXPECT_EQ(10, math_util::cap<int>(15, 0, 10));
|
||||||
expect(math_util::cap<float>(20.5f, 0.0f, 30.0f) == 20.5f);
|
EXPECT_EQ(20.5f, math_util::cap<float>(20.5f, 0.0f, 30.0f));
|
||||||
expect(math_util::cap<float>(1.0f, 0.0f, 2.0f) == 1.0f);
|
EXPECT_EQ(1.0f, math_util::cap<float>(1.0f, 0.0f, 2.0f));
|
||||||
expect(math_util::cap<float>(-2.0f, -5.0f, 5.0f) == -2.0f);
|
EXPECT_EQ(-2.0f, math_util::cap<float>(-2.0f, -5.0f, 5.0f));
|
||||||
expect(math_util::cap<float>(1.0f, 0.0f, 0.0f) == 0);
|
EXPECT_EQ(0, math_util::cap<float>(1.0f, 0.0f, 0.0f));
|
||||||
};
|
}
|
||||||
|
|
||||||
"percentage"_test = [] {
|
TEST(Math, percentage) {
|
||||||
expect(math_util::percentage<float, float>(5.5f, 0.0f, 10.0f) == 55.0f);
|
EXPECT_EQ(55.0f, (math_util::percentage<float, float>(5.5f, 0.0f, 10.0f)));
|
||||||
expect(math_util::percentage<float, int>(5.55f, 0.0f, 10.0f) == 56);
|
EXPECT_EQ(56, (math_util::percentage<float, int>(5.55f, 0.0f, 10.0f)));
|
||||||
expect(math_util::percentage<float, float>(5.25f, 0.0f, 12.0f) == 43.75f);
|
EXPECT_EQ(43.75f, (math_util::percentage<float, float>(5.25f, 0.0f, 12.0f)));
|
||||||
expect(math_util::percentage<int, int>(5, 0, 12) == 41);
|
EXPECT_EQ(41, (math_util::percentage<int, int>(5, 0, 12)));
|
||||||
expect(math_util::percentage<float, float>(20.5f, 0.0f, 100.0f) == 20.5f);
|
EXPECT_EQ(20.5f, (math_util::percentage<float, float>(20.5f, 0.0f, 100.0f)));
|
||||||
expect(math_util::percentage<float, float>(4.5f, 1.0f, 6.0f) == 70.0f);
|
EXPECT_EQ(70.0f, (math_util::percentage<float, float>(4.5f, 1.0f, 6.0f)));
|
||||||
expect(math_util::percentage<float, int>(20.5f, 0.0f, 100.0f) == 21);
|
EXPECT_EQ(21, (math_util::percentage<float, int>(20.5f, 0.0f, 100.0f)));
|
||||||
expect(math_util::percentage<int, int>(4, 2, 6) == 50);
|
EXPECT_EQ(50, (math_util::percentage<int, int>(4, 2, 6)));
|
||||||
expect(math_util::percentage<int, int>(0, -10, 10) == 50);
|
EXPECT_EQ(50, (math_util::percentage<int, int>(0, -10, 10)));
|
||||||
expect(math_util::percentage<int, int>(-10, -10, 10) == 0);
|
EXPECT_EQ(0, (math_util::percentage<int, int>(-10, -10, 10)));
|
||||||
expect(math_util::percentage<int, int>(10, -10, 10) == 100);
|
EXPECT_EQ(100, (math_util::percentage<int, int>(10, -10, 10)));
|
||||||
expect(math_util::percentage(10, 0, 100) == 10);
|
EXPECT_EQ(10, (math_util::percentage(10, 0, 100)));
|
||||||
};
|
}
|
||||||
|
|
||||||
"percentage_to_value"_test = [] {
|
TEST(Math, percentageToValue) {
|
||||||
expect(math_util::percentage_to_value(50, 5) == 3);
|
EXPECT_EQ(3, math_util::percentage_to_value(50, 5));
|
||||||
expect(math_util::percentage_to_value<int, float>(50, 5) == 2.5f);
|
EXPECT_EQ(2.5f, (math_util::percentage_to_value<int, float>(50, 5)));
|
||||||
expect(math_util::percentage_to_value(0, 5) == 0);
|
EXPECT_EQ(0, math_util::percentage_to_value(0, 5));
|
||||||
expect(math_util::percentage_to_value(10, 5) == 1);
|
EXPECT_EQ(1, math_util::percentage_to_value(10, 5));
|
||||||
expect(math_util::percentage_to_value(20, 5) == 1);
|
EXPECT_EQ(1, math_util::percentage_to_value(20, 5));
|
||||||
expect(math_util::percentage_to_value(30, 5) == 2);
|
EXPECT_EQ(2, math_util::percentage_to_value(30, 5));
|
||||||
expect(math_util::percentage_to_value(40, 5) == 2);
|
EXPECT_EQ(2, math_util::percentage_to_value(40, 5));
|
||||||
expect(math_util::percentage_to_value(50, 5) == 3);
|
EXPECT_EQ(3, math_util::percentage_to_value(50, 5));
|
||||||
expect(math_util::percentage_to_value(100, 5) == 5);
|
EXPECT_EQ(5, math_util::percentage_to_value(100, 5));
|
||||||
expect(math_util::percentage_to_value(200, 5) == 5);
|
EXPECT_EQ(5, math_util::percentage_to_value(200, 5));
|
||||||
expect(math_util::percentage_to_value(-30, 5) == 0);
|
EXPECT_EQ(0, math_util::percentage_to_value(-30, 5));
|
||||||
};
|
}
|
||||||
|
|
||||||
"ranged_percentage_to_value"_test = [] {
|
TEST(Math, rangedPercentageToValue) {
|
||||||
expect(math_util::percentage_to_value(50, 200, 300) == 250);
|
EXPECT_EQ(250, math_util::percentage_to_value(50, 200, 300));
|
||||||
expect(math_util::percentage_to_value(50, 1, 5) == 3);
|
EXPECT_EQ(3, math_util::percentage_to_value(50, 1, 5));
|
||||||
};
|
}
|
||||||
|
|
||||||
"round_to_nearest_10"_test = [] {
|
TEST(Math, roundToNearest10) {
|
||||||
expect(math_util::nearest_10(52) == 50);
|
EXPECT_EQ(50, math_util::nearest_10(52));
|
||||||
expect(math_util::nearest_10(9.1) == 10);
|
EXPECT_EQ(10, math_util::nearest_10(9.1));
|
||||||
expect(math_util::nearest_10(95.0) == 100);
|
EXPECT_EQ(100, math_util::nearest_10(95.0));
|
||||||
expect(math_util::nearest_10(94.9) == 90);
|
EXPECT_EQ(90, math_util::nearest_10(94.9));
|
||||||
};
|
}
|
||||||
|
|
||||||
"round_to_nearest_5"_test = [] {
|
TEST(Math, roundToNearest5) {
|
||||||
expect(math_util::nearest_5(52) == 50);
|
EXPECT_EQ(50, math_util::nearest_5(52));
|
||||||
expect(math_util::nearest_5(9.1) == 10);
|
EXPECT_EQ(10, math_util::nearest_5(9.1));
|
||||||
expect(math_util::nearest_5(95.0) == 95);
|
EXPECT_EQ(95, math_util::nearest_5(95.0));
|
||||||
expect(math_util::nearest_5(94.9) == 95);
|
EXPECT_EQ(95, math_util::nearest_5(94.9));
|
||||||
expect(math_util::nearest_5(1) == 0);
|
EXPECT_EQ(0, math_util::nearest_5(1));
|
||||||
expect(math_util::nearest_5(99.99) == 100);
|
EXPECT_EQ(100, math_util::nearest_5(99.99));
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue