Skip to content

Commit

Permalink
Added unit tests for image class
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
1 change: 1 addition & 0 deletions UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/BlueFramework/UnitTests/Core/Ve

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/BlueFramework/UnitTests/ImageProcessing/Color)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/BlueFramework/UnitTests/ImageProcessing/RandomHeightmapGeneration)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/BlueFramework/UnitTests/ImageProcessing/Image)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/BlueFramework/UnitTests/Engine/ClearScreen)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/BlueFramework/UnitTests/Engine/CopyTextureRegion)
Expand Down
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 UnitTests/src/BlueFramework/UnitTests/ImageProcessing/Image/image.cpp
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
}

0 comments on commit 1728925

Please sign in to comment.