[WIP] starting the implementation of color
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* chapitre-01_tests.cpp
|
||||
* 01_tuples.cpp
|
||||
*
|
||||
* Copyright (c) 2015-2024, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -19,7 +19,7 @@
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* @Author: NADAL Jean-Baptiste
|
||||
* @Date: 07/02/2021
|
||||
* @Date: 29/01/2024
|
||||
*
|
||||
*/
|
||||
|
||||
100
tests/02_colors.cpp
Normal file
100
tests/02_colors.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*!
|
||||
* 01_colors.cpp
|
||||
*
|
||||
* Copyright (c) 2015-2024, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* @Author: NADAL Jean-Baptiste
|
||||
* @Date: 30/01/2024
|
||||
*
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "color.h"
|
||||
|
||||
using namespace Raytracer;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("colors are (red,green,blue) tuples", "[Colors]")
|
||||
{
|
||||
Color c(-0.5, 0.4, 1.7);
|
||||
|
||||
REQUIRE(c.red() == -0.5);
|
||||
REQUIRE(c.green() == 0.4);
|
||||
REQUIRE(c.blue() == 1.7);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Colors could be copied", "[Colors]")
|
||||
{
|
||||
Color c1(-0.5, 0.4, 1.7);
|
||||
Color c2;
|
||||
|
||||
c2 = c1;
|
||||
|
||||
REQUIRE(c2.red() == -0.5);
|
||||
REQUIRE(c2.green() == 0.4);
|
||||
REQUIRE(c2.blue() == 1.7);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Adding colors", "[Colors]")
|
||||
{
|
||||
Color c1(0.9, 0.6, 0.75);
|
||||
Color c2(0.7, 0.1, 0.25);
|
||||
|
||||
//Color c3 = c1 + c2;
|
||||
|
||||
REQUIRE((c1 + c2) == Color(1.6, 0.7, 1.0));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Adding colors without modify c1", "[Colors]")
|
||||
{
|
||||
Color c1(0.9, 0.6, 0.75);
|
||||
Color c2(0.7, 0.1, 0.25);
|
||||
|
||||
Color c3 = c1 + c2;
|
||||
|
||||
REQUIRE((c1 + c2) == Color(1.6, 0.7, 1.0));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Subtracting colors", "[Colors]")
|
||||
{
|
||||
Color c1(0.9, 0.6, 0.75);
|
||||
Color c2(0.7, 0.1, 0.25);
|
||||
|
||||
REQUIRE((c1 - c2) == Color(0.2, 0.5, 0.5));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Multiplying a color by a scalar", "[Colors]")
|
||||
{
|
||||
Color c(0.2, 0.3, 0.4);
|
||||
|
||||
REQUIRE(c * 2 == Color(0.4, 0.6, 0.8));
|
||||
}
|
||||
@@ -12,7 +12,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
add_executable(main_test
|
||||
main_test.cpp
|
||||
|
||||
chapitre01_tuples.cpp
|
||||
01_tuples.cpp
|
||||
02_colors.cpp
|
||||
)
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/tests")
|
||||
|
||||
Reference in New Issue
Block a user