Last active
March 26, 2020 13:16
-
-
Save heitor31415/764790981baf657c44befca2ba893dca to your computer and use it in GitHub Desktop.
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
#include <image.h> | |
#include <io_tools.h> | |
namespace igg | |
{ | |
Image::Image(const int &rows, const int &cols) : rows_(rows), cols_(cols) | |
{ | |
// std::cout << "Explicita\n"; | |
data_.reserve(rows_ * cols_); | |
} | |
const int &Image::rows() const { return rows_; } | |
const int &Image::cols() const { return cols_; } | |
int &Image::at(int row, int col) | |
{ | |
return data_.at(row + col * rows_); | |
} | |
/// Returns True if the Image was succesfully fille from the Pgm file | |
bool Image::FillFromPgm(const std::string &file_name) | |
{ | |
io_tools::ImageData reading_image = io_tools::ReadFromPgm(file_name); | |
if (reading_image.rows != 0) // if the image is empty (error on reading) | |
{ | |
rows_ = std::move(reading_image.rows); | |
cols_ = std::move(reading_image.cols); | |
max_val_ = std::move(reading_image.max_val); | |
data_ = std::move(reading_image.data); | |
return true; | |
} | |
return false; | |
} | |
void Image::WriteToPgm(const std::string &file_name) | |
{ | |
io_tools::WriteToPgm({rows_, cols_, max_val_, data_}, file_name); | |
} | |
} // namespace igg | |
//TEST.cpp aqui | |
#include <gtest/gtest.h> | |
#include <vector> | |
#include <image.h> | |
TEST(TestImage, ConstructorTest) | |
{ | |
igg::Image image_specified(500, 500); | |
std::vector<int> vetor(200); | |
EXPECT_EQ(image_specified.cols(), image_specified.rows()); | |
EXPECT_EQ(image_specified.cols(), 500); | |
ASSERT_THROW(image_specified.at(1, 1), std::out_of_range); | |
// ASSERT_ANY_THROW(vetor.at(3) = 3); | |
// EXPECT_EQ(2, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment