Advertisement
perjespersson

C++++

Mar 15th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <stdexcept>
  2. #include <iostream>
  3.  
  4. class Color{
  5. public:
  6. Color(int r, int g, int b, int a);
  7. int get_red();
  8. int get_green();
  9. int get_blue();
  10. int get_alpha();
  11.  
  12. private:
  13. int red;
  14. int green;
  15. int blue;
  16. int alpha;
  17. };
  18.  
  19. //------------------------------------------------------------------//
  20.  
  21. Color::Color(int r, int g, int b, int a):
  22. red{0}, green{0}, blue{0}, alpha{0}
  23. {
  24.  
  25. }
  26.  
  27. int Color::get_red(){
  28. return red;
  29. }
  30.  
  31. int Color::get_green(){
  32. return green;
  33. }
  34.  
  35. int Color::get_blue(){
  36. return blue;
  37. }
  38.  
  39. int Color::get_alpha(){
  40. return blue;
  41. }
  42.  
  43. //------------------------------------------------------------------//
  44.  
  45. // add your Color class here
  46. // you may but are not required to add a header file
  47. // do not modify anything else
  48.  
  49. #define CATCH_CONFIG_MAIN
  50. #include "catch.hpp"
  51. #include <sstream>
  52.  
  53. TEST_CASE("Constructor")
  54. {
  55. Color a{100,200,0,3};
  56.  
  57. CHECK( a.get_red() == 0 );
  58. CHECK( a.get_green() == 0 );
  59. CHECK( a.get_blue() == 0 );
  60. CHECK( a.get_alpha() == 0 );
  61. }
  62.  
  63.  
  64. /*
  65.  
  66. std::string str(Color const& c)
  67. {
  68. std::ostringstream oss;
  69. oss << c;
  70. return oss.str();
  71. }
  72.  
  73. TEST_CASE("construction")
  74. {
  75. CHECK_NOTHROW( (Color{1,255,0,255}) );
  76. CHECK_NOTHROW( (Color{100,200,0}) );
  77. CHECK_NOTHROW( (Color{75,140,60}) );
  78. CHECK_NOTHROW( (Color{128}) );
  79. CHECK_THROWS( (Color{256,-1,256,-1}) );
  80. }
  81.  
  82. TEST_CASE("print")
  83. {
  84. CHECK( str(Color{50,80,20,128}) == "{50, 80, 20}");
  85. }
  86.  
  87. TEST_CASE("add color")
  88. {
  89. Color a{100,200,0};
  90. Color b{50,80,120};
  91. Color c{75,140,60};
  92.  
  93. REQUIRE( str(Color{50,80,20}) == "{50, 80, 20}");
  94.  
  95. CHECK( str(a+b) == str(c) );
  96. CHECK( str(a+c) != str(b) );
  97. CHECK( str(b+c) != str(a) );
  98. }
  99.  
  100. TEST_CASE("add grayscale")
  101. {
  102. Color a{100,200,0};
  103. Color b{100,150,50};
  104.  
  105. REQUIRE( str(Color{50,80,20}) == "{50, 80, 20}");
  106.  
  107. CHECK( str(a+100) == str(b) );
  108. CHECK( str(100+a) == str(b) );
  109. }
  110.  
  111. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement