[FEAT] add operator * and / and magnitude
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "tuple.h"
|
||||
@@ -136,3 +138,66 @@ TEST_CASE("Negative a tuple", "[Tuple][Operations]")
|
||||
|
||||
REQUIRE(-a == Tuple(-1, 2, -3, 4));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Multiplying a tuple by a scalar", "[Tuple][Multiplication]")
|
||||
{
|
||||
Tuple a(1, -2, 3, -4);
|
||||
|
||||
REQUIRE(a * 3.5 == Tuple(3.5, -7, 10.5, -14));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Dividing a tuple by a scalar", "[Tuple][Multiplication]")
|
||||
{
|
||||
Tuple a(1, -2, 3, -4);
|
||||
|
||||
REQUIRE(a / 2 == Tuple(0.5, -1, 1.5, -2));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Computing the magnitude of vector(1,0,0)", "[Tuple][Magnitude]")
|
||||
{
|
||||
Tuple v = Tuple::Vector(1, 0, 0);
|
||||
|
||||
REQUIRE(v.magnitude() == 1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Computing the magnitude of vector(0,1,0)", "[Tuple][Magnitude]")
|
||||
{
|
||||
Tuple v = Tuple::Vector(0, 1, 0);
|
||||
|
||||
REQUIRE(v.magnitude() == 1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Computing the magnitude of vector(0,0,1)", "[Tuple][Magnitude]")
|
||||
{
|
||||
Tuple v = Tuple::Vector(0, 0, 1);
|
||||
|
||||
REQUIRE(v.magnitude() == 1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Computing the magnitude of vector(1,2,3)", "[Tuple][Magnitude]")
|
||||
{
|
||||
Tuple v = Tuple::Vector(1, 2, 3);
|
||||
|
||||
REQUIRE(v.magnitude() == sqrtf(14));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("Computing the magnitude of vector(-1,-2,-3)", "[Tuple][Magnitude]")
|
||||
{
|
||||
Tuple v = Tuple::Vector(-1, -2, -3);
|
||||
|
||||
REQUIRE(v.magnitude() == sqrtf(14));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user