-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
134 additions
and
87 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
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
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
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,62 @@ | ||
#include "pixelator/image.hpp" | ||
|
||
#include "ftxui/screen/color.hpp" | ||
#include "gtest/gtest.h" | ||
|
||
namespace { | ||
using pixelator::Image; | ||
using pixelator::Size; | ||
} // namespace | ||
|
||
TEST(ImageValidationTest, DefaultConstructorCreatesAnEmptyImage) { | ||
const Image image; | ||
EXPECT_TRUE(image.empty()); | ||
EXPECT_EQ(image.size().cols, 0); | ||
EXPECT_EQ(image.size().rows, 0); | ||
EXPECT_EQ(image.cols(), 0); | ||
EXPECT_EQ(image.rows(), 0); | ||
} | ||
|
||
TEST(ImageValidationTest, ImageCreatedWithSizeHasCorrectSize) { | ||
const Image image{Size{10, 20}}; | ||
EXPECT_EQ(image.size().rows, 10); | ||
EXPECT_EQ(image.size().cols, 20); | ||
EXPECT_EQ(image.cols(), 20); | ||
EXPECT_EQ(image.rows(), 10); | ||
} | ||
|
||
TEST(ImageValidationTest, ImageCreatedWithSizeHasCorrectDefaultColor) { | ||
const Image image{Size{10, 20}}; | ||
EXPECT_FALSE(image.empty()); | ||
EXPECT_EQ(image.cols(), 20); | ||
EXPECT_EQ(image.rows(), 10); | ||
for (auto row = 0; row < image.rows(); ++row) { | ||
for (auto col = 0; col < image.cols(); ++col) { | ||
EXPECT_EQ(image.at(row, col), ftxui::Color{}); | ||
} | ||
} | ||
} | ||
|
||
TEST(ImageTest, AtMethodSetsAndReturnsCorrectColor) { | ||
Image image{Size{10, 20}}; | ||
image.at(0, 0) = ftxui::Color::Red; | ||
EXPECT_EQ(image.at(0, 0), ftxui::Color::Red); | ||
} | ||
|
||
TEST(ImageTest, CanBeConstructedByCopyingAnExistingImage) { | ||
Image image{Size{10, 20}}; | ||
image.at(0, 0) = ftxui::Color::Red; | ||
EXPECT_EQ(image.at(0, 0), ftxui::Color::Red); | ||
|
||
const Image image_copy{image}; | ||
EXPECT_EQ(image_copy.at(0, 0), ftxui::Color::Red); | ||
} | ||
|
||
TEST(ImageTest, CanBeConstructedByMovingAnExistingImage) { | ||
Image image{Size{10, 20}}; | ||
image.at(0, 0) = ftxui::Color::Red; | ||
EXPECT_EQ(image.at(0, 0), ftxui::Color::Red); | ||
|
||
const Image image_copy{std::move(image)}; | ||
EXPECT_EQ(image_copy.at(0, 0), ftxui::Color::Red); | ||
} |
50 changes: 50 additions & 0 deletions
50
inject/homework_5/validation_tests/pixelate_image_test.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,50 @@ | ||
#include "pixelator/pixelate_image.hpp" | ||
|
||
#include "pixelator/image.hpp" | ||
#include "pixelator/size.hpp" | ||
#include "pixelator/stb_image_data_view.hpp" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace { | ||
using pixelator::Image; | ||
using pixelator::PixelateImage; | ||
using pixelator::Size; | ||
using pixelator::StbImageDataView; | ||
|
||
const auto kImagePath{"../../pixelator/test_data/test.png"}; | ||
const auto kBlack{ftxui::Color::RGB(0, 0, 0)}; | ||
const auto kWhite{ftxui::Color::RGB(255, 255, 255)}; | ||
} // namespace | ||
|
||
TEST(PixelateImageValidationTest, PassingSameOrBiggerSizeReturnsSameSizedImage) { | ||
const StbImageDataView image{kImagePath}; | ||
const auto size = image.size(); | ||
const auto pixelated_image = PixelateImage(image, size); | ||
const Size bigger_size{size.rows + 10, size.cols + 20}; | ||
const auto pixelated_image_bigger = PixelateImage(image, bigger_size); | ||
ASSERT_FALSE(pixelated_image.empty()); | ||
ASSERT_FALSE(pixelated_image_bigger.empty()); | ||
ASSERT_EQ(image.rows(), pixelated_image.rows()); | ||
ASSERT_EQ(image.cols(), pixelated_image.cols()); | ||
ASSERT_EQ(image.rows(), pixelated_image_bigger.rows()); | ||
ASSERT_EQ(image.cols(), pixelated_image_bigger.cols()); | ||
for (auto row = 0; row < image.rows(); ++row) { | ||
for (auto col = 0; col < image.cols(); ++col) { | ||
EXPECT_EQ(image.at(row, col), pixelated_image.at(row, col)); | ||
EXPECT_EQ(image.at(row, col), pixelated_image_bigger.at(row, col)); | ||
} | ||
} | ||
} | ||
|
||
TEST(PixelateImageValidationTest, PixelateSimpleTest6x4Image) { | ||
const StbImageDataView image{kImagePath}; | ||
const auto pixelated_image = PixelateImage(image, Size{3, 2}); | ||
EXPECT_EQ(pixelated_image.rows(), 3) << "Pixelated image has wrong size."; | ||
EXPECT_EQ(pixelated_image.cols(), 2) << "Pixelated image has wrong size."; | ||
|
||
ASSERT_EQ(pixelated_image.at(0, 0), kBlack) | ||
<< "Pixelated image color is wrong."; | ||
ASSERT_EQ(pixelated_image.at(2, 1), kWhite) | ||
<< "Pixelated image color is wrong."; | ||
} |
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
inject/homework_5/validation_tests/pixelated_image_test.cpp
This file was deleted.
Oops, something went wrong.
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