Files
raytracer_challenge/tests/02_colors.cpp
NADAL Jean-Baptiste 3c88427371 [FIX] Just rename tests
2024-01-31 11:42:27 +01:00

133 lines
3.3 KiB
C++

/*!
* 02_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("[Color] 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("[Color] 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("[Color] Adding colors", "[Colors]")
{
Color c1(0.9, 0.6, 0.75);
Color c2(0.7, 0.1, 0.25);
REQUIRE((c1 + c2) == Color(1.6, 0.7, 1.0));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Color] 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("[Color] 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("[Color] Subtracting 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(0.2, 0.5, 0.5));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Color] 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));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Color] Multiplying a color by a scalar without modify c", "[Colors]")
{
Color c(0.2, 0.3, 0.4);
Color c3 = c * 4;
REQUIRE(c * 2 == Color(0.4, 0.6, 0.8));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Color] Multiplying a colors", "[Colors]")
{
Color c1(1, 0.2, 0.4);
Color c2(0.9, 1, 0.1);
REQUIRE((c1 * c2) == Color(0.9, 0.2, 0.04));
}