Skip to content

Commit 1de46fb

Browse files
Add test fur StatisticsTypeBuilder
1 parent a75c0c9 commit 1de46fb

File tree

6 files changed

+179
-14
lines changed

6 files changed

+179
-14
lines changed

YUViewLib/src/common/Typedef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ template <typename T> struct Range
170170
T min{};
171171
T max{};
172172

173-
bool operator!=(const Range &other) const
173+
bool operator==(const Range &other) const
174174
{
175-
return this->min != other.min || this->max != other.max;
175+
return this->min == other.min && this->max == other.max;
176176
}
177177
};
178178

YUViewLib/src/statistics/ColorMapper.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,19 @@ void ColorMapper::loadPlaylist(const QStringPairList &attributes)
449449
}
450450
}
451451

452-
bool ColorMapper::operator!=(const ColorMapper &other) const
452+
bool ColorMapper::operator==(const ColorMapper &other) const
453453
{
454454
if (this->mappingType != other.mappingType)
455-
return true;
455+
return false;
456456
if (this->mappingType == MappingType::Gradient)
457-
return this->valueRange != other.valueRange ||
458-
this->gradientColorStart != other.gradientColorStart ||
459-
this->gradientColorEnd != other.gradientColorEnd;
457+
return this->valueRange == other.valueRange &&
458+
this->gradientColorStart == other.gradientColorStart &&
459+
this->gradientColorEnd == other.gradientColorEnd;
460460
if (this->mappingType == MappingType::Map)
461-
return this->colorMap != other.colorMap;
461+
return this->colorMap == other.colorMap;
462462
if (this->mappingType == MappingType::Predefined)
463-
return this->valueRange != other.valueRange || this->predefinedType != other.predefinedType;
463+
return this->valueRange == other.valueRange && //
464+
this->predefinedType == other.predefinedType;
464465
return false;
465466
}
466467

YUViewLib/src/statistics/ColorMapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class ColorMapper
130130

131131
// Two colorMappers are identical if they will return the same color when asked for any value.
132132
// When changing the type of one of the mappers, this might not be true anymore.
133-
bool operator!=(const ColorMapper &other) const;
133+
bool operator==(const ColorMapper &other) const;
134134

135135
MappingType mappingType{MappingType::Predefined};
136136

YUViewLib/src/statistics/StatisticsType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ std::vector<StatisticsType::ArrowHead> AllArrowHeads = {StatisticsType::ArrowHea
7373

7474
} // namespace
7575

76+
bool LineDrawStyle::operator==(const LineDrawStyle &other) const
77+
{
78+
return color == other.color && width == other.width && pattern == other.pattern;
79+
}
80+
7681
void StatisticsType::setInitialState()
7782
{
7883
this->init.render = this->render;

YUViewLib/src/statistics/StatisticsType.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ struct LineDrawStyle
5858
double width{0.25};
5959
Pattern pattern{Pattern::Solid};
6060

61-
bool operator!=(const LineDrawStyle &other) const
62-
{
63-
return color != other.color || width != other.width || pattern != other.pattern;
64-
}
61+
bool operator==(const LineDrawStyle &other) const;
6562
};
6663

6764
/* This class defines a type of statistic to render. Each statistics type entry defines the name and
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#include <common/Testing.h>
34+
35+
#include <statistics/StatisticsTypeBuilder.h>
36+
37+
namespace stats::test
38+
{
39+
40+
TEST(StatisticsTypeBuilderTest, DefaultValues)
41+
{
42+
const auto statisticsType = StatisticsTypeBuilder().build();
43+
44+
EXPECT_EQ(statisticsType.typeID, 0);
45+
EXPECT_TRUE(statisticsType.typeName.empty());
46+
EXPECT_TRUE(statisticsType.description.empty());
47+
EXPECT_FALSE(statisticsType.render);
48+
EXPECT_EQ(statisticsType.alphaFactor, 50);
49+
EXPECT_FALSE(statisticsType.valueDataOptions);
50+
EXPECT_FALSE(statisticsType.vectorDataOptions);
51+
EXPECT_FALSE(statisticsType.gridOptions.render);
52+
EXPECT_EQ(statisticsType.gridOptions.style, LineDrawStyle());
53+
EXPECT_FALSE(statisticsType.gridOptions.scaleToZoom);
54+
}
55+
56+
TEST(StatisticsTypeBuilderTest, SetTypeNameDescriptionAndRenderValues)
57+
{
58+
const auto statisticsType = stats::StatisticsTypeBuilder()
59+
.withTypeID(1)
60+
.withTypeName("TestType")
61+
.withDescription("TestDescription")
62+
.withRender(true)
63+
.withAlphaFactor(75)
64+
.build();
65+
66+
EXPECT_EQ(statisticsType.typeID, 1);
67+
EXPECT_EQ(statisticsType.typeName, "TestType");
68+
EXPECT_EQ(statisticsType.description, "TestDescription");
69+
EXPECT_TRUE(statisticsType.render);
70+
EXPECT_EQ(statisticsType.alphaFactor, 75);
71+
}
72+
73+
TEST(StatisticsTypeBuilderTest, SetValueDatDefaultValues)
74+
{
75+
const auto statisticsType = stats::StatisticsTypeBuilder().withValueDataOptions({}).build();
76+
77+
EXPECT_TRUE(statisticsType.valueDataOptions);
78+
EXPECT_EQ(statisticsType.valueDataOptions->render, true);
79+
EXPECT_EQ(statisticsType.valueDataOptions->scaleToBlockSize, false);
80+
EXPECT_EQ(statisticsType.valueDataOptions->colorMapper, color::ColorMapper());
81+
}
82+
83+
TEST(StatisticsTypeBuilderTest, SetValueDataCustomValues)
84+
{
85+
const auto colorMapper = color::ColorMapper({0, 255}, color::PredefinedType::Jet);
86+
87+
const auto statisticsType =
88+
stats::StatisticsTypeBuilder()
89+
.withValueDataOptions(
90+
{.render = false, .scaleToBlockSize = true, .colorMapper = colorMapper})
91+
.build();
92+
93+
EXPECT_TRUE(statisticsType.valueDataOptions);
94+
EXPECT_EQ(statisticsType.valueDataOptions->render, false);
95+
EXPECT_EQ(statisticsType.valueDataOptions->scaleToBlockSize, true);
96+
EXPECT_EQ(statisticsType.valueDataOptions->colorMapper, colorMapper);
97+
}
98+
99+
TEST(StatisticsTypeBuilderTest, SetVectorDataDefaultValues)
100+
{
101+
const auto statisticsType = StatisticsTypeBuilder().withVectorDataOptions({}).build();
102+
103+
EXPECT_TRUE(statisticsType.vectorDataOptions);
104+
EXPECT_TRUE(statisticsType.vectorDataOptions->render);
105+
EXPECT_TRUE(statisticsType.vectorDataOptions->renderDataValues);
106+
EXPECT_FALSE(statisticsType.vectorDataOptions->scaleToZoom);
107+
EXPECT_EQ(statisticsType.vectorDataOptions->style, LineDrawStyle());
108+
EXPECT_EQ(statisticsType.vectorDataOptions->scale, 0);
109+
EXPECT_FALSE(statisticsType.vectorDataOptions->mapToColor);
110+
EXPECT_EQ(statisticsType.vectorDataOptions->arrowHead, StatisticsType::ArrowHead::arrow);
111+
}
112+
113+
TEST(StatisticsTypeBuilderTest, SetVectorDataCustomValues)
114+
{
115+
const auto lineDrawStyle = LineDrawStyle(Color(255, 0, 0), 2, Pattern::DashDot);
116+
117+
const auto statisticsType = StatisticsTypeBuilder()
118+
.withVectorDataOptions({
119+
.render = false,
120+
.renderDataValues = false,
121+
.scaleToZoom = true,
122+
.style = lineDrawStyle,
123+
.scale = 3,
124+
.mapToColor = true,
125+
.arrowHead = StatisticsType::ArrowHead::circle,
126+
})
127+
.build();
128+
129+
EXPECT_TRUE(statisticsType.vectorDataOptions);
130+
EXPECT_FALSE(statisticsType.vectorDataOptions->render);
131+
EXPECT_FALSE(statisticsType.vectorDataOptions->renderDataValues);
132+
EXPECT_TRUE(statisticsType.vectorDataOptions->scaleToZoom);
133+
EXPECT_EQ(statisticsType.vectorDataOptions->style, lineDrawStyle);
134+
EXPECT_EQ(statisticsType.vectorDataOptions->scale, 3);
135+
EXPECT_TRUE(statisticsType.vectorDataOptions->mapToColor);
136+
EXPECT_EQ(statisticsType.vectorDataOptions->arrowHead, StatisticsType::ArrowHead::circle);
137+
}
138+
139+
TEST(StatisticsTypeBuilderTest, SetGridOptionsDefaultValues)
140+
{
141+
const auto statisticsType = StatisticsTypeBuilder().withGridOptions({}).build();
142+
143+
EXPECT_FALSE(statisticsType.gridOptions.render);
144+
EXPECT_EQ(statisticsType.gridOptions.style, LineDrawStyle());
145+
EXPECT_FALSE(statisticsType.gridOptions.scaleToZoom);
146+
}
147+
148+
TEST(StatisticsTypeBuilderTest, SetGridOptionsCustomValues)
149+
{
150+
const auto lineDrawStyle = LineDrawStyle(Color(123, 44, 99), 5, Pattern::DashDot);
151+
152+
const auto statisticsType =
153+
StatisticsTypeBuilder()
154+
.withGridOptions({.render = true, .style = lineDrawStyle, .scaleToZoom = true})
155+
.build();
156+
157+
EXPECT_TRUE(statisticsType.gridOptions.render);
158+
EXPECT_EQ(statisticsType.gridOptions.style, lineDrawStyle);
159+
EXPECT_TRUE(statisticsType.gridOptions.scaleToZoom);
160+
}
161+
162+
} // namespace stats::test

0 commit comments

Comments
 (0)