[FEAT] Add test and Tuplus object
This commit is contained in:
22
.PVS-Studio/State/WindowState.json
Normal file
22
.PVS-Studio/State/WindowState.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"isDataChanged": false,
|
||||||
|
"filters": {
|
||||||
|
"code": "",
|
||||||
|
"message": "",
|
||||||
|
"files": "",
|
||||||
|
"level": [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
],
|
||||||
|
"isColumnFiltersVisible": true,
|
||||||
|
"isLevelFiltersVisible": true,
|
||||||
|
"isGroupFiltersVisible": true,
|
||||||
|
"type": [
|
||||||
|
"General",
|
||||||
|
"Optimization"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"loadableProcessIds": []
|
||||||
|
}
|
||||||
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"Raytracer"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -2,23 +2,29 @@ cmake_minimum_required(VERSION 3.14)
|
|||||||
project(raytracing_challenge)
|
project(raytracing_challenge)
|
||||||
|
|
||||||
# GoogleTest requires at least C++14
|
# GoogleTest requires at least C++14
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
googletest
|
googletest
|
||||||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
|
||||||
)
|
)
|
||||||
|
|
||||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
FetchContent_MakeAvailable(googletest)
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
|
include_directories("${CMAKE_SOURCE_DIR}/src")
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
rc_tests
|
rc_tests
|
||||||
tests/chapitre01_tests.cpp
|
|
||||||
|
src/tuple.cpp
|
||||||
|
|
||||||
|
tests/chapitre01_tuples.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
rc_tests
|
rc_tests
|
||||||
|
|||||||
@@ -3,3 +3,6 @@
|
|||||||
## Le Livre est ici:
|
## Le Livre est ici:
|
||||||
|
|
||||||
https://lire.amazon.fr/?asin=B07Q84TQ91&ref_=kwl_kr_iv_rec_1
|
https://lire.amazon.fr/?asin=B07Q84TQ91&ref_=kwl_kr_iv_rec_1
|
||||||
|
|
||||||
|
|
||||||
|
https://github.com/sraaphorst/raytracer-cpp/blob/b57794ce9f4ed80d782711adb9131f3e3097d4b0/CMakeLists.txt
|
||||||
|
|||||||
65
src/tuple.cpp
Normal file
65
src/tuple.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*!
|
||||||
|
* tuple.cpp
|
||||||
|
*
|
||||||
|
* Copyright (c) 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: 29/01/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||||
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include "tuple.h"
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
Raytracer::Tuple::Tuple(float a_x, float a_y, float a_z, float a_w) : m_x(a_x), m_y(a_y), m_z(a_z), m_w(a_w)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
float Raytracer::Tuple::x(void) const
|
||||||
|
{
|
||||||
|
return m_x;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
float Raytracer::Tuple::y(void) const
|
||||||
|
{
|
||||||
|
return m_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
float Raytracer::Tuple::z(void) const
|
||||||
|
{
|
||||||
|
return m_z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
float Raytracer::Tuple::w(void) const
|
||||||
|
{
|
||||||
|
return m_w;
|
||||||
|
}
|
||||||
58
src/tuple.h
Normal file
58
src/tuple.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*!
|
||||||
|
* tuple.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 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: 29/01/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RAYTRACER_TUPLE_H
|
||||||
|
#define _RAYTRACER_TUPLE_H
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#define kRCTuplesPoint 1.0
|
||||||
|
#define kRCTuplesVetor 0.0
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
namespace Raytracer
|
||||||
|
{
|
||||||
|
class Tuple
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tuple(float x, float y, float z, float w);
|
||||||
|
|
||||||
|
// Access
|
||||||
|
float x(void) const;
|
||||||
|
float y(void) const;
|
||||||
|
float z(void) const;
|
||||||
|
float w(void) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float m_x;
|
||||||
|
float m_y;
|
||||||
|
float m_z;
|
||||||
|
float m_w;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _RAYTRACER_TUPLE_H */
|
||||||
24
src/vector.cpp
Normal file
24
src/vector.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*!
|
||||||
|
* vector.cpp
|
||||||
|
*
|
||||||
|
* Copyright (c) 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: 29/01/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
24
src/vector.h
Normal file
24
src/vector.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*!
|
||||||
|
* vector.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 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: 29/01/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
* MA 02110-1301 USA
|
* MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* @Author: NADAL Jean-Baptiste
|
* @Author: NADAL Jean-Baptiste
|
||||||
* @Date: 07/02/2021
|
* @Date: 07/02/2021
|
||||||
*
|
*
|
||||||
@@ -30,10 +30,13 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
// Demonstrate some basic assertions.
|
#include "tuple.h"
|
||||||
TEST(HelloTest, BasicAssertions) {
|
|
||||||
// Expect two strings not to be equal.
|
TEST(RaytracerTuple, CreateBasicTuple)
|
||||||
EXPECT_STRNE("hello", "world");
|
{
|
||||||
// Expect equality.
|
Raytracer::Tuple t(4.3, -4.2, 3.1, 1.0);
|
||||||
EXPECT_EQ(7 * 6, 42);
|
EXPECT_FLOAT_EQ(t.x(), 4.3);
|
||||||
|
EXPECT_FLOAT_EQ(t.y(), -4.2);
|
||||||
|
EXPECT_FLOAT_EQ(t.z(), 3.1);
|
||||||
|
EXPECT_FLOAT_EQ(t.w(), 1.0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user