#include "blitz/misc/Test.h"

#include "blitz/common/Vector.h"

using namespace blitz;

template <typename T>
static void TestVec2() {
	Vec2<T> vec1{1, 2};
	Vec2<T> vec2{3, 4};
	T scalar = static_cast<T>(3);

	blitz_test_assert(vec1 + vec2 == Vec2<T>{4, 6});
	blitz_test_assert(vec2 - vec1 == Vec2<T>{2, 2});
	blitz_test_assert(scalar * vec2 == Vec2<T>{9, 12});

	vec1 += {5, 7};
	vec2 -= {2, 1};

	blitz_test_assert(vec1 == Vec2<T>{6, 9});
	blitz_test_assert(vec2 == Vec2<T>{1, 3});
}

template <typename T>
static void TestVec3() {
	Vec3<T> vec1{1, 2, 3};
	Vec3<T> vec2{4, 6, 9};
	T scalar = static_cast<T>(3);

	blitz_test_assert(vec1 + vec2 == Vec3<T>{5, 8, 12});
	blitz_test_assert(vec2 - vec1 == Vec3<T>{3, 4, 6});
	blitz_test_assert(scalar * vec2 == Vec3<T>{12, 18, 27});

	vec1 += {5, 7, 10};
	vec2 -= {2, 1, 3};

	blitz_test_assert(vec1 == Vec3<T>{6, 9, 13});
	blitz_test_assert(vec2 == Vec3<T>{2, 5, 6});
}

template <typename T>
static void TestVec4() {
	Vec4<T> vec1{1, 2, 3, 4};
	Vec4<T> vec2{9, 7, 10, 8};
	T scalar = static_cast<T>(3);

	blitz_test_assert(vec1 + vec2 == Vec4<T>{10, 9, 13, 12});
	blitz_test_assert(vec2 - vec1 == Vec4<T>{8, 5, 7, 4});
	blitz_test_assert(scalar * vec2 == Vec4<T>{27, 21, 30, 24});

	vec1 += {5, 7, 1, 10};
	vec2 -= {2, 1, 5, 4};

	blitz_test_assert(vec1 == Vec4<T>{6, 9, 4, 14});
	blitz_test_assert(vec2 == Vec4<T>{7, 6, 5, 4});
}

template <typename T>
static void TestVectors() {
	TestVec2<T>();
	TestVec3<T>();
	TestVec4<T>();
}

int main(int argc, const char* args[]) {
	TestVectors<double>();
	TestVectors<float>();
	TestVectors<int>();
	TestVectors<unsigned int>();

	return BLITZ_TEST_SUCCESSFUL;
}