[FEAT] Add matrix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* 02_colors.cpp
|
||||
* 02_1_colors.cpp
|
||||
*
|
||||
* Copyright (c) 2015-2024, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* 03_canvas.cpp
|
||||
* 02_2_canvas.cpp
|
||||
*
|
||||
* Copyright (c) 2015-2024, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*!
|
||||
* 03_matrix.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: 01/02/2024
|
||||
*
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "matrix.h"
|
||||
|
||||
using namespace Raytracer;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[Matrix] Constructing and inspecting a 4x4 matrix", "[Matrix]")
|
||||
{
|
||||
Matrix m = {
|
||||
{ 1, 2, 3, 4},
|
||||
{ 5.5, 6.5, 7.5, 8.5},
|
||||
{ 9, 10, 11, 12},
|
||||
{13.5, 14.5, 15.5, 16.5}
|
||||
};
|
||||
|
||||
REQUIRE(m.rows() == 4);
|
||||
REQUIRE(m.cols() == 4);
|
||||
|
||||
REQUIRE(m[0][0] == 1);
|
||||
REQUIRE(m[0][3] == 4);
|
||||
REQUIRE(m[1][0] == 5.5);
|
||||
REQUIRE(m[1][2] == 7.5);
|
||||
REQUIRE(m[2][2] == 11);
|
||||
REQUIRE(m[3][0] == 13.5);
|
||||
REQUIRE(m[3][2] == 15.5);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[Matrix] A 2x2 matrix ought to be representable", "[Matrix]")
|
||||
{
|
||||
Matrix m = {
|
||||
{-3, 5},
|
||||
{ 1, -2}
|
||||
};
|
||||
|
||||
REQUIRE(m.rows() == 2);
|
||||
REQUIRE(m.cols() == 2);
|
||||
|
||||
REQUIRE(m[0][0] == -3);
|
||||
REQUIRE(m[0][1] == 5);
|
||||
REQUIRE(m[1][0] == 1);
|
||||
REQUIRE(m[1][1] == -2);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[Matrix] A 3x3 matrix ought to be representable", "[Matrix]")
|
||||
{
|
||||
Matrix m = {
|
||||
{-3, 5, 0},
|
||||
{ 1, -2, -7},
|
||||
{ 0, 1, 1}
|
||||
};
|
||||
|
||||
REQUIRE(m.rows() == 3);
|
||||
REQUIRE(m.cols() == 3);
|
||||
|
||||
REQUIRE(m[0][0] == -3);
|
||||
REQUIRE(m[1][1] == -2);
|
||||
REQUIRE(m[2][2] == 1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[Matrix] Matrix equality with identical matrices", "[Matrix]")
|
||||
{
|
||||
Matrix a = {
|
||||
{1, 2, 3, 4},
|
||||
{5, 6, 7, 8},
|
||||
{9, 8, 7, 6},
|
||||
{5, 4, 3, 2}
|
||||
};
|
||||
Matrix b = {
|
||||
{1, 2, 3, 4},
|
||||
{5, 6, 7, 8},
|
||||
{9, 8, 7, 6},
|
||||
{5, 4, 3, 2}
|
||||
};
|
||||
|
||||
REQUIRE(a == b);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[Matrix] Matrix equality with different matrices", "[Matrix]")
|
||||
{
|
||||
Matrix a = {
|
||||
{1, 2, 3, 4},
|
||||
{5, 6, 7, 8},
|
||||
{9, 8, 7, 6},
|
||||
{5, 4, 3, 2}
|
||||
};
|
||||
Matrix b = {
|
||||
{2, 3, 4, 5},
|
||||
{6, 7, 8, 9},
|
||||
{8, 7, 6, 5},
|
||||
{4, 3, 2, 1}
|
||||
};
|
||||
|
||||
REQUIRE(a != b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user