Skip to content

Commit

Permalink
Add test fur StatisticsTypeBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Jan 16, 2025
1 parent a75c0c9 commit 1de46fb
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 14 deletions.
4 changes: 2 additions & 2 deletions YUViewLib/src/common/Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ template <typename T> struct Range
T min{};
T max{};

bool operator!=(const Range &other) const
bool operator==(const Range &other) const
{
return this->min != other.min || this->max != other.max;
return this->min == other.min && this->max == other.max;
}
};

Expand Down
15 changes: 8 additions & 7 deletions YUViewLib/src/statistics/ColorMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,18 +449,19 @@ void ColorMapper::loadPlaylist(const QStringPairList &attributes)
}
}

bool ColorMapper::operator!=(const ColorMapper &other) const
bool ColorMapper::operator==(const ColorMapper &other) const
{
if (this->mappingType != other.mappingType)
return true;
return false;
if (this->mappingType == MappingType::Gradient)
return this->valueRange != other.valueRange ||
this->gradientColorStart != other.gradientColorStart ||
this->gradientColorEnd != other.gradientColorEnd;
return this->valueRange == other.valueRange &&
this->gradientColorStart == other.gradientColorStart &&
this->gradientColorEnd == other.gradientColorEnd;
if (this->mappingType == MappingType::Map)
return this->colorMap != other.colorMap;
return this->colorMap == other.colorMap;
if (this->mappingType == MappingType::Predefined)
return this->valueRange != other.valueRange || this->predefinedType != other.predefinedType;
return this->valueRange == other.valueRange && //
this->predefinedType == other.predefinedType;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/statistics/ColorMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ColorMapper

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

MappingType mappingType{MappingType::Predefined};

Expand Down
5 changes: 5 additions & 0 deletions YUViewLib/src/statistics/StatisticsType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ std::vector<StatisticsType::ArrowHead> AllArrowHeads = {StatisticsType::ArrowHea

} // namespace

bool LineDrawStyle::operator==(const LineDrawStyle &other) const
{
return color == other.color && width == other.width && pattern == other.pattern;
}

void StatisticsType::setInitialState()
{
this->init.render = this->render;
Expand Down
5 changes: 1 addition & 4 deletions YUViewLib/src/statistics/StatisticsType.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ struct LineDrawStyle
double width{0.25};
Pattern pattern{Pattern::Solid};

bool operator!=(const LineDrawStyle &other) const
{
return color != other.color || width != other.width || pattern != other.pattern;
}
bool operator==(const LineDrawStyle &other) const;
};

/* This class defines a type of statistic to render. Each statistics type entry defines the name and
Expand Down
162 changes: 162 additions & 0 deletions YUViewUnitTest/statistics/StatisticsTypeBuilderTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <common/Testing.h>

#include <statistics/StatisticsTypeBuilder.h>

namespace stats::test
{

TEST(StatisticsTypeBuilderTest, DefaultValues)
{
const auto statisticsType = StatisticsTypeBuilder().build();

EXPECT_EQ(statisticsType.typeID, 0);
EXPECT_TRUE(statisticsType.typeName.empty());
EXPECT_TRUE(statisticsType.description.empty());
EXPECT_FALSE(statisticsType.render);
EXPECT_EQ(statisticsType.alphaFactor, 50);
EXPECT_FALSE(statisticsType.valueDataOptions);
EXPECT_FALSE(statisticsType.vectorDataOptions);
EXPECT_FALSE(statisticsType.gridOptions.render);
EXPECT_EQ(statisticsType.gridOptions.style, LineDrawStyle());
EXPECT_FALSE(statisticsType.gridOptions.scaleToZoom);
}

TEST(StatisticsTypeBuilderTest, SetTypeNameDescriptionAndRenderValues)
{
const auto statisticsType = stats::StatisticsTypeBuilder()
.withTypeID(1)
.withTypeName("TestType")
.withDescription("TestDescription")
.withRender(true)
.withAlphaFactor(75)
.build();

EXPECT_EQ(statisticsType.typeID, 1);
EXPECT_EQ(statisticsType.typeName, "TestType");
EXPECT_EQ(statisticsType.description, "TestDescription");
EXPECT_TRUE(statisticsType.render);
EXPECT_EQ(statisticsType.alphaFactor, 75);
}

TEST(StatisticsTypeBuilderTest, SetValueDatDefaultValues)
{
const auto statisticsType = stats::StatisticsTypeBuilder().withValueDataOptions({}).build();

EXPECT_TRUE(statisticsType.valueDataOptions);
EXPECT_EQ(statisticsType.valueDataOptions->render, true);
EXPECT_EQ(statisticsType.valueDataOptions->scaleToBlockSize, false);
EXPECT_EQ(statisticsType.valueDataOptions->colorMapper, color::ColorMapper());
}

TEST(StatisticsTypeBuilderTest, SetValueDataCustomValues)
{
const auto colorMapper = color::ColorMapper({0, 255}, color::PredefinedType::Jet);

const auto statisticsType =
stats::StatisticsTypeBuilder()
.withValueDataOptions(
{.render = false, .scaleToBlockSize = true, .colorMapper = colorMapper})
.build();

EXPECT_TRUE(statisticsType.valueDataOptions);
EXPECT_EQ(statisticsType.valueDataOptions->render, false);
EXPECT_EQ(statisticsType.valueDataOptions->scaleToBlockSize, true);
EXPECT_EQ(statisticsType.valueDataOptions->colorMapper, colorMapper);
}

TEST(StatisticsTypeBuilderTest, SetVectorDataDefaultValues)
{
const auto statisticsType = StatisticsTypeBuilder().withVectorDataOptions({}).build();

EXPECT_TRUE(statisticsType.vectorDataOptions);
EXPECT_TRUE(statisticsType.vectorDataOptions->render);
EXPECT_TRUE(statisticsType.vectorDataOptions->renderDataValues);
EXPECT_FALSE(statisticsType.vectorDataOptions->scaleToZoom);
EXPECT_EQ(statisticsType.vectorDataOptions->style, LineDrawStyle());
EXPECT_EQ(statisticsType.vectorDataOptions->scale, 0);
EXPECT_FALSE(statisticsType.vectorDataOptions->mapToColor);
EXPECT_EQ(statisticsType.vectorDataOptions->arrowHead, StatisticsType::ArrowHead::arrow);
}

TEST(StatisticsTypeBuilderTest, SetVectorDataCustomValues)
{
const auto lineDrawStyle = LineDrawStyle(Color(255, 0, 0), 2, Pattern::DashDot);

const auto statisticsType = StatisticsTypeBuilder()
.withVectorDataOptions({
.render = false,
.renderDataValues = false,
.scaleToZoom = true,
.style = lineDrawStyle,
.scale = 3,
.mapToColor = true,
.arrowHead = StatisticsType::ArrowHead::circle,
})
.build();

EXPECT_TRUE(statisticsType.vectorDataOptions);
EXPECT_FALSE(statisticsType.vectorDataOptions->render);
EXPECT_FALSE(statisticsType.vectorDataOptions->renderDataValues);
EXPECT_TRUE(statisticsType.vectorDataOptions->scaleToZoom);
EXPECT_EQ(statisticsType.vectorDataOptions->style, lineDrawStyle);
EXPECT_EQ(statisticsType.vectorDataOptions->scale, 3);
EXPECT_TRUE(statisticsType.vectorDataOptions->mapToColor);
EXPECT_EQ(statisticsType.vectorDataOptions->arrowHead, StatisticsType::ArrowHead::circle);
}

TEST(StatisticsTypeBuilderTest, SetGridOptionsDefaultValues)
{
const auto statisticsType = StatisticsTypeBuilder().withGridOptions({}).build();

EXPECT_FALSE(statisticsType.gridOptions.render);
EXPECT_EQ(statisticsType.gridOptions.style, LineDrawStyle());
EXPECT_FALSE(statisticsType.gridOptions.scaleToZoom);
}

TEST(StatisticsTypeBuilderTest, SetGridOptionsCustomValues)
{
const auto lineDrawStyle = LineDrawStyle(Color(123, 44, 99), 5, Pattern::DashDot);

const auto statisticsType =
StatisticsTypeBuilder()
.withGridOptions({.render = true, .style = lineDrawStyle, .scaleToZoom = true})
.build();

EXPECT_TRUE(statisticsType.gridOptions.render);
EXPECT_EQ(statisticsType.gridOptions.style, lineDrawStyle);
EXPECT_TRUE(statisticsType.gridOptions.scaleToZoom);
}

} // namespace stats::test

0 comments on commit 1de46fb

Please sign in to comment.