Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdexcept>
- #include <iostream>
- class Color{
- public:
- Color(int r, int g, int b, int a);
- int get_red();
- int get_green();
- int get_blue();
- int get_alpha();
- private:
- int red;
- int green;
- int blue;
- int alpha;
- };
- //------------------------------------------------------------------//
- Color::Color(int r, int g, int b, int a):
- red{0}, green{0}, blue{0}, alpha{0}
- {
- }
- int Color::get_red(){
- return red;
- }
- int Color::get_green(){
- return green;
- }
- int Color::get_blue(){
- return blue;
- }
- int Color::get_alpha(){
- return blue;
- }
- //------------------------------------------------------------------//
- // add your Color class here
- // you may but are not required to add a header file
- // do not modify anything else
- #define CATCH_CONFIG_MAIN
- #include "catch.hpp"
- #include <sstream>
- TEST_CASE("Constructor")
- {
- Color a{100,200,0,3};
- CHECK( a.get_red() == 0 );
- CHECK( a.get_green() == 0 );
- CHECK( a.get_blue() == 0 );
- CHECK( a.get_alpha() == 0 );
- }
- /*
- std::string str(Color const& c)
- {
- std::ostringstream oss;
- oss << c;
- return oss.str();
- }
- TEST_CASE("construction")
- {
- CHECK_NOTHROW( (Color{1,255,0,255}) );
- CHECK_NOTHROW( (Color{100,200,0}) );
- CHECK_NOTHROW( (Color{75,140,60}) );
- CHECK_NOTHROW( (Color{128}) );
- CHECK_THROWS( (Color{256,-1,256,-1}) );
- }
- TEST_CASE("print")
- {
- CHECK( str(Color{50,80,20,128}) == "{50, 80, 20}");
- }
- TEST_CASE("add color")
- {
- Color a{100,200,0};
- Color b{50,80,120};
- Color c{75,140,60};
- REQUIRE( str(Color{50,80,20}) == "{50, 80, 20}");
- CHECK( str(a+b) == str(c) );
- CHECK( str(a+c) != str(b) );
- CHECK( str(b+c) != str(a) );
- }
- TEST_CASE("add grayscale")
- {
- Color a{100,200,0};
- Color b{100,150,50};
- REQUIRE( str(Color{50,80,20}) == "{50, 80, 20}");
- CHECK( str(a+100) == str(b) );
- CHECK( str(100+a) == str(b) );
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement