1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <QDebug>
#include "util/math.h"
#include "util/rescaler.h"
using ::testing::ElementsAre;
namespace {
class RescalerUtilsTest : public testing::Test {
};
TEST_F(RescalerUtilsTest, Test) {
double result;
// test upper border
result = RescalerUtils::linearToOneByX(100, 0, 100, 1000);
EXPECT_DOUBLE_EQ(result, 1000);
result = RescalerUtils::linearToOneByX(100, 50, 100, 1000);
EXPECT_DOUBLE_EQ(result, 1000);
result = RescalerUtils::linearToOneByX(50, 40, 50, 1000);
EXPECT_DOUBLE_EQ(result, 1000);
// test lower border
result = RescalerUtils::linearToOneByX(0, 0, 100, 1000);
EXPECT_DOUBLE_EQ(result, 1);
result = RescalerUtils::linearToOneByX(50, 50, 100, 1000);
EXPECT_DOUBLE_EQ(result, 1);
result = RescalerUtils::linearToOneByX(40, 40, 50, 1000);
EXPECT_DOUBLE_EQ(result, 1);
// test upper border inverse
result = RescalerUtils::oneByXToLinear(100, 100, 0, 1000);
EXPECT_DOUBLE_EQ(result, 1000);
result = RescalerUtils::oneByXToLinear(100, 100, 50, 1000);
EXPECT_DOUBLE_EQ(result, 1000);
result = RescalerUtils::oneByXToLinear(50, 50, 50, 1000);
EXPECT_DOUBLE_EQ(result, 1000);
// test lower border inverse
result = RescalerUtils::oneByXToLinear(1, 100, 0, 1000);
EXPECT_DOUBLE_EQ(result, 0);
result = RescalerUtils::oneByXToLinear(1, 50, 100, 1000);
EXPECT_TRUE(fabs(result - 100) < 0.0000000001);
result = RescalerUtils::oneByXToLinear(1, 40, 50, 1000);
EXPECT_TRUE(fabs(result - 50) < 0.0000000001);
// Test Roundtrip
// test upper border
result = RescalerUtils::linearToOneByX(50, 0, 100, 1000);
result = RescalerUtils::oneByXToLinear(result, 1000, 0, 100);
EXPECT_TRUE(fabs(result - 50) < 0.0000000001);
}
} // namespace
|