Line data Source code
1 : #include "pch.h" 2 : 3 : #include "linear_func.h" 4 : 5 : class LinearFuncTest : public ::testing::Test { 6 : protected: 7 : // Maps (1, 4) -> (100, -100) 8 : LinearFunc dut; 9 : 10 2 : void SetUp() override { 11 2 : dut.configure(1, 100, 4, -100, -110, 110); 12 2 : } 13 : }; 14 : 15 : #define test_point(in, out) \ 16 : { \ 17 : auto result = dut.convert(in); \ 18 : \ 19 : EXPECT_TRUE(result.Valid); \ 20 : ASSERT_NEAR(result.Value, (out), EPS4D) << "Not " << out << " for " << in; \ 21 : } 22 : 23 : #define test_point_invalid(in) \ 24 : { EXPECT_FALSE(dut.convert(in).Valid); } 25 : 26 4 : TEST_F(LinearFuncTest, TestInRange) { 27 2 : test_point(2.5, 0); 28 2 : test_point(1, 100); 29 2 : test_point(4, -100); 30 : } 31 : 32 4 : TEST_F(LinearFuncTest, TestOutOfRange) { 33 2 : test_point(1, 100); 34 1 : test_point_invalid(0.5); 35 : 36 2 : test_point(4, -100); 37 1 : test_point_invalid(4.5); 38 : }