//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * 四次元テクスチャ座標テスト実装
 * @author Junpee
 */

#include "Test/stdafx.h"
#include "Core/Primitive/TexCoord4Test.h"
#include "Core/Primitive/TexCoord4.h"

//------------------------------------------------------------------------------
// コンストラクタ
TexCoord4Test::TexCoord4Test(String name) : TestCase(name){
}
//------------------------------------------------------------------------------
// テストスィートの取得
Test* TexCoord4Test::suite(){
	TestSuite* suite = new TestSuite("TexCoord4Test");
	suite->addTest(new TestCaller(TexCoord4Test, testConstructor));
	suite->addTest(new TestCaller(TexCoord4Test, testFixedNumber));
	suite->addTest(new TestCaller(TexCoord4Test, testSetValue));
	suite->addTest(new TestCaller(TexCoord4Test, testArithmetic));
	suite->addTest(new TestCaller(TexCoord4Test, testSubstitutionArithmetic));
	suite->addTest(new TestCaller(TexCoord4Test, testLogicalOperation));
	suite->addTest(new TestCaller(TexCoord4Test, testToString));
	return suite;
}
//------------------------------------------------------------------------------
// コンストラクタテスト
void TexCoord4Test::testConstructor(){
	TexCoord4 uv0;
	TestEquals(16, (int)sizeof(uv0));
	uv0.u = 1.f;
	uv0.v = 2.f;
	uv0.w = 3.f;
	uv0.x = 4.f;
	TexCoord4 uv1;
	uv1.array[0] = 1.f;
	uv1.array[1] = 2.f;
	uv1.array[2] = 3.f;
	uv1.array[3] = 4.f;
	TestAssert(uv0 == uv1);
	TexCoord4 uv2(1.f, 2.f, 3.f, 4.f);
	TestAssert(uv0 == uv2);
	float array[] = { 1.f, 2.f, 3.f, 4.f };
	TexCoord4 uv3((const float* const)array);
	TestAssert(uv0 == uv3);
	TexCoord4 uv4(uv0);
	TestAssert(uv0 == uv4);
	TexCoord4 uv5;
	uv5 = uv0;
	TestAssert(uv0 == uv5);
}
//------------------------------------------------------------------------------
// 定数テスト
void TexCoord4Test::testFixedNumber(){
	TexCoord4 uv0;
	uv0.set(0.f, 0.f, 0.f, 0.f);
	TestAssert(uv0 == TexCoord4::zero);
	uv0.set(1.f, 1.f, 1.f, 1.f);
	TestAssert(uv0 == TexCoord4::unit);
	uv0.set(1.f, 0.f, 0.f, 0.f);
	TestAssert(uv0 == TexCoord4::unitU);
	uv0.set(0.f, 1.f, 0.f, 0.f);
	TestAssert(uv0 == TexCoord4::unitV);
	uv0.set(0.f, 0.f, 1.f, 0.f);
	TestAssert(uv0 == TexCoord4::unitW);
	uv0.set(0.f, 0.f, 0.f, 1.f);
	TestAssert(uv0 == TexCoord4::unitX);
}
//------------------------------------------------------------------------------
// 値の設定テスト
void TexCoord4Test::testSetValue(){
	TexCoord4 uv0(1.f, 2.f, 3.f, 4.f);
	TexCoord4 uv1;
	uv1.set(1.f, 2.f, 3.f, 4.f);
	TestAssert(uv0 == uv1);
	float array[] = { 4.f, 3.f, 2.f, 1.f };
	uv1.set(array);
	TestAssert(uv0 != uv1);
	uv0.set(4.f, 3.f, 2.f, 1.f);
	TestAssert(uv0 == uv1);
}
//------------------------------------------------------------------------------
// 演算
void TexCoord4Test::testArithmetic(){
	const TexCoord4 uv0(0.f, 1.f, 2.f, 3.f), uv1(1.f, 2.f, 3.f, 4.f),
		uv2(1.f, 3.f, 5.f, 7.f);
	TestAssert(uv2 == (uv0 + uv1));
	TestAssert(uv0 == (uv2 - uv1));
	const TexCoord4 uv3(0.f, 2.f, 4.f, 6.f);
	TestAssert(uv3 == (uv0 * 2.f));
	TestAssert(uv3 == (2.f * uv0));
	TestAssert(uv0 == (+uv0));
	const TexCoord4 uv4(0.f, -1.f, -2.f, -3.f);
	TestAssert(uv0 == (-uv4));
}
//------------------------------------------------------------------------------
// 代入演算
void TexCoord4Test::testSubstitutionArithmetic(){
	TexCoord4 uv0(0.f, 1.f, 2.f, 3.f), uv1(1.f, 1.f, 1.f, 1.f);
	TestAssert(TexCoord4(1.f, 2.f, 3.f, 4.f) == (uv0 += uv1));
	TestAssert(TexCoord4(0.f, 1.f, 2.f, 3.f) == (uv0 -= uv1));
	TestAssert(TexCoord4(0.f, 2.f, 4.f, 6.f) == (uv0 *= 2.f));
}
//------------------------------------------------------------------------------
// 論理演算テスト
void TexCoord4Test::testLogicalOperation(){
	TexCoord4 uv0(0.f, 0.f, 0.f, 0.f), uv1(1.f, 1.f, 1.f, 1.f),
		uv2(0.f, 0.f, 0.f, 0.f);
	TestAssert(!(uv0 == uv1));
	TestAssert(uv0 == uv2);
	TestAssert(uv0 != uv1);
	TestAssert(!(uv0 != uv2));
	TestAssert(uv0.epsilonEquals(uv1, 1.f));
	TestAssert(uv0.notEpsilonEquals(uv1, 0.5f));
	TestAssert(!uv0.notEpsilonEquals(uv1, 1.f));
	TestAssert(!uv0.notEpsilonEquals(uv2, 0.f));
}
//------------------------------------------------------------------------------
// 文字列テスト
void TexCoord4Test::testToString(){
	TexCoord4 uv0(12345678.f, 1234.5678f, 12.345678f, 1.2345678f);
	TestEquals("( 12345678.00000000, 1234.56774902, 12.34567833, 1.23456776 )",
		uv0.toString());
}
//------------------------------------------------------------------------------
