Files
raytracer_challenge/tests/03_canvas.cpp
NADAL Jean-Baptiste 770b784383 [FEAT]Add Canvas
2024-01-31 15:18:47 +01:00

59 lines
1.6 KiB
C++

/*!
* 03_canvas.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: 31/01/2024
*
*/
/*---------------------------------------------------------------------------*/
#include <catch.hpp>
#include "canvas.h"
using namespace Raytracer;
/* ------------------------------------------------------------------------- */
TEST_CASE("[Canvas] Creating a canvas", "[Canvas]")
{
Canvas c(10, 20);
REQUIRE(c.width() == 10);
REQUIRE(c.height() == 20);
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 20; ++j)
REQUIRE(c.pixel_at(2, 3) == Color(0, 0, 0));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Canvas] Writing pixels to a canvas", "[Canvas]")
{
Canvas c(10, 20);
Color red(1, 0, 0);
c.write_pixel(2, 3, red);
REQUIRE(c.pixel_at(2, 3) == red);
}