-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started implementing unit tests for image class, operators == and != as well as fill function.
- Loading branch information
Helge Hecht
committed
Aug 6, 2020
1 parent
7002541
commit 1728925
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
UnitTests/src/BlueFramework/UnitTests/ImageProcessing/Image/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# This file is part of BlueFramework, a simple 3D engine. | ||
# Copyright (c) 2020 Technical University of Munich | ||
# Chair of Computational Modeling and Simulation. | ||
# | ||
# BlueFramework is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License Version 3 | ||
# as published by the Free Software Foundation. | ||
# | ||
# BlueFramework 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/>. | ||
# | ||
|
||
file(GLOB BlueFramework_UnitTests_ImageProcessing_Image *.*) | ||
|
||
source_group(BlueFramework\\UnitTests\\ImageProcessing FILES ${BlueFramework_UnitTests_ImageProcessing_Image}) | ||
|
||
add_executable(Image | ||
${BlueFramework_UnitTests_Source} | ||
${BlueFramework_UnitTests_ImageProcessing_Image} | ||
) | ||
|
||
|
||
target_link_libraries(Image | ||
BlueFramework.Core | ||
BlueFramework.ImageProcessing | ||
gtest | ||
gtest_main | ||
) | ||
|
||
add_test( | ||
NAME ImageTest | ||
COMMAND Image | ||
) | ||
|
||
set_target_properties(Image PROPERTIES FOLDER "BlueFramework/UnitTests/ImageProcessing") |
102 changes: 102 additions & 0 deletions
102
UnitTests/src/BlueFramework/UnitTests/ImageProcessing/Image/image.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
This file is part of BlueFramework, a simple 3D engine. | ||
Copyright (c) 2020 Technical University of Munich | ||
Chair of Computational Modeling and Simulation. | ||
BlueFramework is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License Version 3 | ||
as published by the Free Software Foundation. | ||
BlueFramework 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 <gtest/gtest.h> | ||
#include <BlueFramework/ImageProcessing/Image.h> | ||
#include <BlueFramework/ImageProcessing/colorConstants.h> | ||
|
||
using namespace testing; | ||
|
||
class ImageTest : public Test { | ||
|
||
public: | ||
~ImageTest() override { | ||
} | ||
|
||
protected: | ||
void SetUp() override { | ||
} | ||
|
||
void TearDown() override { | ||
} | ||
}; | ||
|
||
TEST_F(ImageTest, GivenImage100x100x3f_AfterFill_AllPixelsHaveFillColor) { | ||
// Arrange | ||
const int width = 100; | ||
const int height = 100; | ||
|
||
const buw::Color3f fillColor = buw::ColorConstants3f::aliceBlue(); | ||
|
||
buw::Image3f image = buw::Image3f(width, height); | ||
|
||
// Act | ||
image.fill(fillColor); | ||
|
||
// Assert | ||
for (int x = 0; x < image.getWidth(); x++) { | ||
for (int y = 0; y < image.getHeight(); ++y) { | ||
auto color = image.getPixelColor(x, y); | ||
EXPECT_EQ(color, fillColor); | ||
EXPECT_NE(color, buw::ColorConstants3f::antiqueWhite()); | ||
} | ||
} | ||
|
||
// Annihilate | ||
} | ||
|
||
TEST_F(ImageTest, GivenEqualImages_OperatorEqual_ReturnsTrue) { | ||
// Arrange | ||
const int width = 100; | ||
const int height = 100; | ||
|
||
const buw::Color3f fillColor = buw::ColorConstants3f::aliceBlue(); | ||
|
||
buw::Image3f first = buw::Image3f(width, height); | ||
buw::Image3f second = buw::Image3f(width, height); | ||
|
||
// Act | ||
first.fill(fillColor); | ||
second.fill(fillColor); | ||
|
||
// Assert | ||
EXPECT_EQ(first, second); | ||
|
||
// Annihilate | ||
} | ||
|
||
TEST_F(ImageTest, GivenNonEqualImages_OperatorEqual_ReturnsFalse) { | ||
// Arrange | ||
const int width = 100; | ||
const int height = 100; | ||
|
||
const buw::Color3f firstFillColor = buw::ColorConstants3f::aliceBlue(); | ||
const buw::Color3f secondFillColor = buw::ColorConstants3f::antiqueWhite(); | ||
|
||
buw::Image3f first = buw::Image3f(width, height); | ||
buw::Image3f second = buw::Image3f(width, height); | ||
|
||
// Act | ||
first.fill(firstFillColor); | ||
second.fill(secondFillColor); | ||
|
||
// Assert | ||
EXPECT_NE(first, second); | ||
|
||
// Annihilate | ||
} |