/*! * 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 #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)); }