Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
113 lines (100 sloc) 2.01 KB
#include "Vectors.hpp"
#include <gtest/gtest.h>
#include <iostream>
using namespace testing;
using namespace raytracer;
TEST(TestVector, testCompoundAdd)
{
Vector c1(1, 2, 3);
Vector c2(2, 3, 4);
Vector expected(3, 5, 7);
c1+=c2;
EXPECT_TRUE( expected == c1 );
}
TEST(TestVector, testCompoundSub)
{
Vector c1(1, 2, 3);
Vector c2(2, 3, 4);
Vector expected(-1, -1, -1);
c1-=c2;
EXPECT_TRUE( expected == c1 );
}
TEST(TestVector, testCompoundMul)
{
Vector c1(1, 2, 3);
Scalar s = 2;
Vector expected(2, 4, 6);
c1*=s;
EXPECT_TRUE( expected == c1 );
}
TEST(TestVector, testCompoundDiv)
{
Vector c1(1, 2, 3);
Scalar s = 2;
Vector expected(0.5, 1, 1.5);
c1/=s;
EXPECT_TRUE( expected == c1 );
}
TEST(TestVector, testAdd)
{
Vector c1(1, 2, 3);
Vector c2(2, 3, 4);
Vector expected(3, 5, 7);
Vector res;
res = c1+c2;
EXPECT_TRUE( expected == res );
}
TEST(TestVector, testSub)
{
Vector c1(1, 2, 3);
Vector c2(2, 3, 4);
Vector expected(-1, -1, -1);
Vector res;
res = c1-c2;
EXPECT_TRUE( expected == res );
}
TEST(TestVector, testMul)
{
Vector c1(1, 2, 3);
Scalar s = 2;
Vector expected(2, 4, 6);
Vector res;
res = c1 * s;
EXPECT_TRUE( expected == res );
res = s * c1;
EXPECT_TRUE( expected == res );
}
TEST(TestVector, testDiv)
{
Vector c1(1, 2, 3);
Scalar s = 2;
Vector expected(0.5, 1, 1.5);
Vector res;
res = c1 / s;
EXPECT_TRUE( expected == res );
}
TEST(TestVector, testDotProduct)
{
Vector c1(1, 2, 3);
Vector c2(2, 3, 4);
Scalar expected = 20;
Scalar res;
res = c1.dotProduct(c2);
EXPECT_EQ( expected,res );
}
TEST(TestVector, testMagnitude)
{
Vector c1(1, 2, 3);
Scalar expected = 14;
Scalar res;
res = c1.magnitude();
EXPECT_EQ( expected,res );
}
TEST(TestVector, testNormalize)
{
Vector c1(1, 2, 3);
Vector expected(1/14.0,1/7.0,3/14.0);
Vector res;
res = c1.normalize();
EXPECT_TRUE( expected == res );
}