示例#1
0
文件: mbh.c 项目: hvds/seq
void test_a(void) {
	bhp a;
	int i;
	void* v;
	a = mbh_new((void*)NULL, &mbh_compare_int);
	test_cycle(a);
	for (i = 0; i < 3; ++i) {
		mbh_insert(a, I2P(i));
	}
	test_b();
	i = mbh_size(a);
	if (i != 3) {
		++g_fail;
		printf("Error: expected suspended heap to have size 3, got %d\n", i);
	}
	for (i = 0; i < 3; ++i) {
		v = mbh_shift(a);
		if (P2I(v) != i) {
			++g_fail;
			printf("Error: heap a corrupted by heap b: expected %d, got %d\n",
					i, P2I(v));
		}
		++g_test;
	}
}
示例#2
0
TEST(CSSTest, Specificity_Relational)
{

	CSSSpecificity test_a(0, 0, 0, 0);
	CSSSpecificity test_b(0, 0, 0, 0);

	ASSERT_TRUE(test_a <= test_b);
	ASSERT_TRUE(test_a >= test_b);
	ASSERT_TRUE(test_b <= test_a);
	ASSERT_TRUE(test_b >= test_a);

	test_a = CSSSpecificity(0, 0, 0, 0);
	test_b = CSSSpecificity(0, 0, 0, 1);

	ASSERT_TRUE(test_a < test_b);
	ASSERT_FALSE(test_a > test_b);

	CSSSpecificity test_c1(1, 0, 0, 0);
	CSSSpecificity test_c2(0, 1, 0, 0);
	CSSSpecificity test_c3(0, 0, 1, 0);
	CSSSpecificity test_c4(0, 0, 0, 1);

	ASSERT_TRUE(test_c1 != test_c2);
	ASSERT_FALSE(test_c1 < test_c2);
	ASSERT_TRUE(test_c1 > test_c2);

	ASSERT_TRUE(test_c2 != test_c3);
	ASSERT_FALSE(test_c2 < test_c3);
	ASSERT_TRUE(test_c2 > test_c3);

	ASSERT_TRUE(test_c3 != test_c4);
	ASSERT_FALSE(test_c3 < test_c4);
	ASSERT_TRUE(test_c3 > test_c4);

}
示例#3
0
TEST(CSSTest, Selector_Count)
{

	CSSSelector test_a("p");

	ASSERT_EQ(1, test_a.count());

	CSSSelector test_b("h1, h2, h3");

	ASSERT_EQ(3, test_b.count());

	CSSSelector test_c("p span");

	ASSERT_EQ(1, test_c.count());

	CSSSelector test_d("p.section");

	ASSERT_EQ(1, test_d.count());

	CSSSelector test_e(".bold");

	ASSERT_EQ(1, test_e.count());

	CSSSelector test_f("#id");

	ASSERT_EQ(1, test_f.count());

}
示例#4
0
void TestApp::test_matrix_mat3()
{
	Console::write_line("  Class: Mat3");

	Console::write_line("   Function: inverse()");
	{
		Mat3d test_src(2, 3, 4, 2, -5, 2, -3, 6, -3);
		Mat3d test_inv;
		Mat3d test_dest;
		Mat3d test_ident = Mat3d::identity();

		test_dest = test_src;
		test_dest.inverse();
		test_dest = test_dest * test_src;

		if (test_ident != test_dest) fail();

		Mat4d test_4d(test_src);
		Mat3d test_3d(test_4d);
		if (test_3d != test_src) fail();

		test_4d =test_src;
		test_3d =test_4d;
		if (test_3d != test_src) fail();
	}

	Mat3i test_a(3, 1, 2, 4, 5 ,6, 4, 2, 1);
	Mat3i test_b(4, 7, 2, 5, 3, 5, 2, 9, 3);

	Console::write_line("   Function: multiply() and operator");
	{
		Mat3i result = test_b * test_a;
		Mat3i answer(21, 42, 17, 53, 97, 51, 28, 43, 21);
		if (result != answer) fail();

		result = Mat3i::multiply(test_b, test_a);
		if (result != answer) fail();

	}

	Console::write_line("   Function: add() and operator");
	{
		Mat3i result = test_a + test_b;
		if (result != Mat3i(7, 8, 4, 9, 8, 11, 6, 11, 4)) fail();

		result = Mat3i::add(test_a, test_b);
		if (result != Mat3i(7, 8, 4, 9, 8, 11, 6, 11, 4)) fail();

	}

	Console::write_line("   Function: subtract() and operator");
	{
		Mat3i result = test_a - test_b;
		if (result != Mat3i(-1, -6, 0, -1, 2, 1, 2, -7, -2)) fail();

		result = Mat3i::subtract(test_a, test_b);
		if (result != Mat3i(-1, -6, 0, -1, 2, 1, 2, -7, -2)) fail();
	}
}
示例#5
0
TEST(CSSTest, Specificity_CopyConstructor)
{

	CSSSpecificity test_a(0, 0, 0, 0);
	CSSSpecificity test_b(test_a);

	ASSERT_TRUE(test_a == test_b);

}
示例#6
0
文件: morefunc.C 项目: 0day-ci/gcc
int main()
{
  A* ap = new A();
  B* bp = new B();

  test_a(ap);
  test_b(bp);

#ifdef _PROFILE_USE
  new_func(10);
#endif

}
示例#7
0
TEST(CSSTest, Selector_Specificity)
{

	CSSSelector selector_a("p");
	CSSSpecificity test_a(0, 0, 0, 1);

	ASSERT_TRUE(selector_a.specificity == test_a);

	CSSSelector selector_b("h1, h2, h3");
	CSSSpecificity test_b(0, 0, 0, 3);

	ASSERT_TRUE(selector_b.specificity == test_b);

	/*
	CSSSelector test_c("p span");

	ASSERT_EQ(1, test_c.count());
	*/

	CSSSelector selector_d("p.section");
	CSSSpecificity test_d(0, 0, 1, 1);

	ASSERT_TRUE(selector_d.specificity == test_d);

	CSSSelector selector_e(".bold");
	CSSSpecificity test_e(0, 0, 1, 0);

	ASSERT_TRUE(selector_e.specificity == test_e);

	CSSSelector selector_f("#id");
	CSSSpecificity test_f(0, 1, 0, 0);

	ASSERT_TRUE(selector_f.specificity == test_f);

	CSSSelector selector_g("span#id");
	CSSSpecificity test_g(0, 1, 0, 1);

	ASSERT_TRUE(selector_g.specificity == test_g);

	CSSSelector selector_h("span#id, p.hello, br");
	CSSSpecificity test_h(0, 1, 1, 3);

	ASSERT_TRUE(selector_h.specificity == test_h);

}
示例#8
0
TEST(CSSTest, Specificity_Equality)
{

	CSSSpecificity test_a(0, 0, 0, 0);
	CSSSpecificity test_b(0, 0, 0, 0);

	ASSERT_TRUE(test_a == test_b);

	CSSSpecificity test_c1(1, 0, 0, 0);
	CSSSpecificity test_c2(0, 1, 0, 0);
	CSSSpecificity test_c3(0, 0, 1, 0);
	CSSSpecificity test_c4(0, 0, 0, 1);

	ASSERT_TRUE(test_a != test_c1);
	ASSERT_TRUE(test_a != test_c2);
	ASSERT_TRUE(test_a != test_c3);
	ASSERT_TRUE(test_a != test_c4);

}
示例#9
0
TEST(CSSTest, Selector_Matches)
{

	CSSSelector test_a("p");

	ASSERT_TRUE(test_a.matches("p"));

	CSSSelector test_b("h1, h2, h3");

	ASSERT_TRUE(test_b.matches("h1"));
	ASSERT_TRUE(test_b.matches("h2"));
	ASSERT_TRUE(test_b.matches("h3"));

	/*
	CSSSelector test_c("p span");

	ASSERT_EQ(1, test_c.count());
	*/

	CSSSelector test_d("p.section");

	ASSERT_TRUE(test_d.matches("p.section"));

	CSSSelector test_e(".bold");

	ASSERT_TRUE(test_e.matches(".bold"));

	CSSSelector test_f("#id");

	ASSERT_TRUE(test_f.matches("#id"));

	CSSSelector test_g("span#id");

	ASSERT_TRUE(test_g.matches("span#id"));


}
示例#10
0
int main(){
	test_a();
	test_b();
}
示例#11
0
文件: test.c 项目: huntinux/C
int main()
{
	test_a();
	test_b();
	return 0;
}
示例#12
0
void TestApp::test_vector2(void)
{
    Console::write_line(" Header: cl_vector.h");
    Console::write_line("  Class: Vec2");

    Console::write_line("   Function: rotate()");
    {
        Vec2i test_a;
        Vec2i hotspot(1,3);

        test_a = Vec2i(4,5);
        test_a.rotate(hotspot, Angle(0, angle_degrees));
        if (test_a != Vec2i(4, 5))  fail();

        test_a = Vec2i(4,5);
        test_a.rotate(hotspot, Angle(90, angle_degrees));
        if (test_a != Vec2i(-1, 6))  fail();

        test_a = Vec2i(4,5);
        test_a.rotate(hotspot, Angle(180, angle_degrees));
        if (test_a != Vec2i(-2, 1))  fail();

        test_a = Vec2i(4,5);
        test_a.rotate(hotspot, Angle(270, angle_degrees));
        if (test_a != Vec2i(3, 0))  fail();

        test_a = Vec2i(4,5);
        test_a.rotate(hotspot, Angle(360, angle_degrees));
        if (test_a != Vec2i(4, 5))  fail();

        test_a = Vec2i(4,5);
        test_a.rotate(Vec2i(0,0), Angle(180, angle_degrees));
        if (test_a != Vec2i(-4, -5))  fail();

    }

    Console::write_line("   Function: distance()");
    {
        Vec2d test_a(2.0,3.0);
        Vec2d test_b(3.0,4.0);

        if (test_a.distance(test_b) != sqrt(1.0 + 1.0 ))  fail();
    }
    Console::write_line("   Function: normalize()");
    {
        Vec2d testi(3.0,4.0);
        testi.normalize();
        if (testi !=  Vec2d(3.0/sqrt(25.0), 4.0/sqrt(25.0)))  fail();
    }

    Console::write_line("   Function: static normalize()");
    {
        Vec2d testi(3.0,4.0);
        if (Vec2d::normalize(testi) !=  Vec2d(3.0/sqrt(25.0), 4.0/sqrt(25.0)))  fail();
    }

    Console::write_line("   Function: length()");
    {
        Vec2d testi(3.0,4.0);
        if (testi.length() != sqrt(25.0 ))  fail();
    }

    Console::write_line("   Function: dot()");
    {
        Vec2d test_a(3.0,4.0);
        Vec2d test_b(13.0,14.0);
        if (test_a.dot(test_b) != ((3.0 * 13.0)+ (4.0*14.0)))  fail();
    }

    Console::write_line("   Function: operator += (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd += Vec2d(1.0, 2.0);

        if (testd.x != 3.5) fail();
        if (testd.y != 5.5) fail();

        Vec2i testi(2, 3);
        testi += Vec2i(1, 2);
        if (testi.x != 3) fail();
        if (testi.y != 5) fail();

    }

    Console::write_line("   Function: operator += ( Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd += valued;

        if (testd.x != 4.5) fail();
        if (testd.y != 5.5) fail();

        Vec2i testi(2, 3);
        int valuei = 2;
        testi += valuei;
        if (testi.x != 4) fail();
        if (testi.y != 5) fail();

    }

    Console::write_line("   Function: operator + (Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd = testd + valued;

        if (testd.x != 4.5) fail();
        if (testd.y != 5.5) fail();

        Vec2i testi(2, 3);
        int valuei = 2;
        testi = testi + valuei;
        if (testi.x != 4) fail();
        if (testi.y != 5) fail();

    }

    Console::write_line("   Function: operator + (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd = testd + Vec2d(1.5, 2.5);

        if (testd.x != 4.0) fail();
        if (testd.y != 6.0) fail();

        Vec2i testi(2, 3);
        testi = testi + Vec2i(1, 2);
        if (testi.x != 3) fail();
        if (testi.y != 5) fail();

    }

    Console::write_line("   Function: operator -= (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd -= Vec2d(1.0, 2.0);

        if (testd.x != 1.5) fail();
        if (testd.y != 1.5) fail();

        Vec2i testi(2, 3);
        testi -= Vec2i(1, 2);
        if (testi.x != 1) fail();
        if (testi.y != 1) fail();

    }

    Console::write_line("   Function: operator -= ( Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd -= valued;

        if (testd.x != 0.5) fail();
        if (testd.y != 1.5) fail();

        Vec2i testi(2, 3);
        int valuei = 2;
        testi -= valuei;
        if (testi.x != 0) fail();
        if (testi.y != 1) fail();

    }

    Console::write_line("   Function: operator - (Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd = testd - valued;

        if (testd.x != 0.5) fail();
        if (testd.y != 1.5) fail();

        Vec2i testi(2, 3);
        int valuei = 2;
        testi = testi - valuei;
        if (testi.x != 0) fail();
        if (testi.y != 1) fail();

    }

    Console::write_line("   Function: operator - (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd = testd - Vec2d(1.5, 2.5);

        if (testd.x != 1.0) fail();
        if (testd.y != 1.0) fail();

        Vec2i testi(2, 3);
        testi = testi - Vec2i(1, 2);
        if (testi.x != 1) fail();
        if (testi.y != 1) fail();

    }

    Console::write_line("   Function: operator *= (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd *= Vec2d(1.0, 2.0);

        if (testd.x != 2.5) fail();
        if (testd.y != 7.0) fail();

        Vec2i testi(2, 3);
        testi *= Vec2i(1, 2);
        if (testi.x != 2) fail();
        if (testi.y != 6) fail();

    }

    Console::write_line("   Function: operator *= ( Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd *= valued;

        if (testd.x != 5.0) fail();
        if (testd.y != 7.0) fail();

        Vec2i testi(2, 3);
        int valuei = 2;
        testi *= valuei;
        if (testi.x != 4) fail();
        if (testi.y != 6) fail();
    }

    Console::write_line("   Function: operator * (Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd = testd * valued;

        if (testd.x != 5.0) fail();
        if (testd.y != 7.0) fail();

        Vec2i testi(2, 3);
        int valuei = 2;
        testi = testi * valuei;
        if (testi.x != 4) fail();
        if (testi.y != 6) fail();

    }

    Console::write_line("   Function: operator * (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd = testd * Vec2d(1.5, 2.5);

        if (testd.x != 3.75) fail();
        if (testd.y != 8.75) fail();

        Vec2i testi(2, 3);
        testi = testi * Vec2i(1, 2);
        if (testi.x != 2) fail();
        if (testi.y != 6) fail();

    }

    Console::write_line("   Function: operator /= (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd /= Vec2d(1.0, 2.0);

        if (testd.x != 2.5) fail();
        if (testd.y != 1.75) fail();

        Vec2i testi(2, 10);
        testi /= Vec2i(1, 2);
        if (testi.x != 2) fail();
        if (testi.y != 5) fail();

    }

    Console::write_line("   Function: operator /= ( Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd /= valued;

        if (testd.x != 1.25) fail();
        if (testd.y != 1.75) fail();

        Vec2i testi(2, 10);
        int valuei = 2;
        testi /= valuei;
        if (testi.x != 1) fail();
        if (testi.y != 5) fail();
    }

    Console::write_line("   Function: operator / (Type value)");
    {
        Vec2d testd(2.5, 3.5);
        double valued = 2.0;
        testd = testd / valued;

        if (testd.x != 1.25) fail();
        if (testd.y != 1.75) fail();

        Vec2i testi(2, 10);
        int valuei = 2;
        testi = testi / valuei;
        if (testi.x != 1) fail();
        if (testi.y != 5) fail();

    }

    Console::write_line("   Function: operator / (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd = testd / Vec2d(1.0, 2.5);

        if (testd.x != 2.5) fail();
        if (testd.y != 1.4) fail();

        Vec2i testi(2, 10);
        testi = testi / Vec2i(1, 2);
        if (testi.x != 2) fail();
        if (testi.y != 5) fail();

    }

    Console::write_line("   Function: operator = (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        testd = Vec2d(1.0, 2.0);

        if (testd.x != 1.0) fail();
        if (testd.y != 2.0) fail();

        Vec2i testi(2, 3);
        testi = Vec2i(1, 2);
        if (testi.x != 1) fail();
        if (testi.y != 2) fail();

    }

    Console::write_line("   Function: operator == (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        if (testd == Vec2d(1.0, 2.0)) fail();
        if (testd == Vec2d(2.5, 2.0)) fail();
        if (!(testd == Vec2d(2.5, 3.5))) fail();

        Vec2i testi(2, 3);
        if (testi == Vec2i(1, 2)) fail();
        if (testi == Vec2i(2, 2)) fail();
        if (!(testi == Vec2i(2, 3))) fail();
    }

    Console::write_line("   Function: operator != (const Vec2<Type>& vector)");
    {
        Vec2d testd(2.5, 3.5);
        if (!(testd != Vec2d(1.0, 2.0))) fail();
        if (!(testd != Vec2d(2.5, 2.0))) fail();
        if ((testd != Vec2d(2.5, 3.5))) fail();

        Vec2i testi(2, 3);
        if (!(testi != Vec2i(1, 2))) fail();
        if (!(testi != Vec2i(2, 2))) fail();
        if ((testi != Vec2i(2, 3))) fail();
    }

    Console::write_line("   Function: round()");
    {
        Vec2d testd(2.0, 2.5);
        testd.round();

        if (testd.x != 2.0) fail();
        if (testd.y != 3.0) fail();

        Vec2f testf(2.0f, 2.5f);
        testf.round();

        if (testf.x != 2.0f) fail();
        if (testf.y != 3.0f) fail();
    }

    Console::write_line("   Function: static round()");
    {
        Vec2d testd(2.0, 2.5);
        Vec2d destd = Vec2d::round(testd);

        if (destd.x != 2.0) fail();
        if (destd.y != 3.0) fail();

        Vec2f testf(2.0f, 2.5f);
        Vec2f destf = Vec2f::round(testf);

        if (destf.x != 2.0f) fail();
        if (destf.y != 3.0f) fail();
    }
}
示例#13
0
void TestApp::test_vector3(void)
{
    Console::write_line(" Header: cl_vector.h");
    Console::write_line("  Class: Vec3");

    Console::write_line("   Function: distance()");
    {
        Vec3d test_a(2.0,3.0,4.0);
        Vec3d test_b(3.0,4.0,5.0);

        if (test_a.distance(test_b) != sqrt(1.0 + 1.0 + 1.0 ))  fail();
    }

    Console::write_line("   Function: normalize()");
    {
        Vec3d testi(3.0,4.0,5.0);
        testi.normalize();
        if (testi !=  Vec3d(3.0/sqrt(50.0), 4.0/sqrt(50.0), 5.0/sqrt(50.0)))  fail();
    }

    Console::write_line("   Function: static normalize()");
    {
        Vec3d testi(3.0,4.0,5.0);
        if (Vec3d::normalize(testi) !=  Vec3d(3.0/sqrt(50.0), 4.0/sqrt(50.0), 5.0/sqrt(50.0)))  fail();
    }

    Console::write_line("   Function: length()");
    {
        Vec3d testi(3.0,4.0,5.0);
        if (testi.length() != sqrt(50.0 ))  fail();
    }

    Console::write_line("   Function: dot()");
    {
        Vec3d test_a(3.0,4.0,5.0);
        Vec3d test_b(13.0,14.0,15.0);
        if (test_a.dot(test_b) != ((3.0 * 13.0)+ (4.0*14.0) + (5.0 * 15.0)))  fail();
    }

    Console::write_line("   Function: operator += (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd += Vec3d(1.0, 2.0, 3.0);

        if (testd.x != 3.5) fail();
        if (testd.y != 5.5) fail();
        if (testd.z != 7.5) fail();

        Vec3i testi(2, 3, 4);
        testi += Vec3i(1, 2, 3);
        if (testi.x != 3) fail();
        if (testi.y != 5) fail();
        if (testi.z != 7) fail();

    }

    Console::write_line("   Function: operator += ( Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd += valued;

        if (testd.x != 4.5) fail();
        if (testd.y != 5.5) fail();
        if (testd.z != 6.5) fail();

        Vec3i testi(2, 3, 4);
        int valuei = 2;
        testi += valuei;
        if (testi.x != 4) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();

    }

    Console::write_line("   Function: operator + (Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd = testd + valued;

        if (testd.x != 4.5) fail();
        if (testd.y != 5.5) fail();
        if (testd.z != 6.5) fail();

        Vec3i testi(2, 3, 4);
        int valuei = 2;
        testi = testi + valuei;
        if (testi.x != 4) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();

    }

    Console::write_line("   Function: operator + (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd = testd + Vec3d(1.5, 2.5, 3.5);

        if (testd.x != 4.0) fail();
        if (testd.y != 6.0) fail();
        if (testd.z != 8.0) fail();

        Vec3i testi(2, 3, 4);
        testi = testi + Vec3i(1, 2, 3);
        if (testi.x != 3) fail();
        if (testi.y != 5) fail();
        if (testi.z != 7) fail();

    }

    Console::write_line("   Function: operator -= (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd -= Vec3d(1.0, 2.0, 3.0);

        if (testd.x != 1.5) fail();
        if (testd.y != 1.5) fail();
        if (testd.z != 1.5) fail();

        Vec3i testi(2, 3, 4);
        testi -= Vec3i(1, 2, 3);
        if (testi.x != 1) fail();
        if (testi.y != 1) fail();
        if (testi.z != 1) fail();

    }

    Console::write_line("   Function: operator -= ( Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd -= valued;

        if (testd.x != 0.5) fail();
        if (testd.y != 1.5) fail();
        if (testd.z != 2.5) fail();

        Vec3i testi(2, 3, 4);
        int valuei = 2;
        testi -= valuei;
        if (testi.x != 0) fail();
        if (testi.y != 1) fail();
        if (testi.z != 2) fail();

    }

    Console::write_line("   Function: operator - (Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd = testd - valued;

        if (testd.x != 0.5) fail();
        if (testd.y != 1.5) fail();
        if (testd.z != 2.5) fail();

        Vec3i testi(2, 3, 4);
        int valuei = 2;
        testi = testi - valuei;
        if (testi.x != 0) fail();
        if (testi.y != 1) fail();
        if (testi.z != 2) fail();

    }

    Console::write_line("   Function: operator - (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd = testd - Vec3d(1.5, 2.5, 3.5);

        if (testd.x != 1.0) fail();
        if (testd.y != 1.0) fail();
        if (testd.z != 1.0) fail();

        Vec3i testi(2, 3, 4);
        testi = testi - Vec3i(1, 2, 3);
        if (testi.x != 1) fail();
        if (testi.y != 1) fail();
        if (testi.z != 1) fail();

    }

    Console::write_line("   Function: operator *= (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd *= Vec3d(1.0, 2.0, 3.0);

        if (testd.x != 2.5) fail();
        if (testd.y != 7.0) fail();
        if (testd.z != 13.5) fail();

        Vec3i testi(2, 3, 4);
        testi *= Vec3i(1, 2, 3);
        if (testi.x != 2) fail();
        if (testi.y != 6) fail();
        if (testi.z != 12) fail();

    }

    Console::write_line("   Function: operator *= ( Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd *= valued;

        if (testd.x != 5.0) fail();
        if (testd.y != 7.0) fail();
        if (testd.z != 9.0) fail();

        Vec3i testi(2, 3, 4);
        int valuei = 2;
        testi *= valuei;
        if (testi.x != 4) fail();
        if (testi.y != 6) fail();
        if (testi.z != 8) fail();

    }

    Console::write_line("   Function: operator * (Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd = testd * valued;

        if (testd.x != 5.0) fail();
        if (testd.y != 7.0) fail();
        if (testd.z != 9.0) fail();

        Vec3i testi(2, 3, 4);
        int valuei = 2;
        testi = testi * valuei;
        if (testi.x != 4) fail();
        if (testi.y != 6) fail();
        if (testi.z != 8) fail();

    }

    Console::write_line("   Function: operator * (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd = testd * Vec3d(1.5, 2.5, 3.5);

        if (testd.x != 3.75) fail();
        if (testd.y != 8.75) fail();
        if (testd.z != 15.75) fail();

        Vec3i testi(2, 3, 4);
        testi = testi * Vec3i(1, 2, 3);
        if (testi.x != 2) fail();
        if (testi.y != 6) fail();
        if (testi.z != 12) fail();

    }

    Console::write_line("   Function: operator /= (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd /= Vec3d(1.0, 2.0, 3.0);

        if (testd.x != 2.5) fail();
        if (testd.y != 1.75) fail();
        if (testd.z != 1.5) fail();

        Vec3i testi(2, 10, 20);
        testi /= Vec3i(1, 2, 3);
        if (testi.x != 2) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();

    }

    Console::write_line("   Function: operator /= ( Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd /= valued;

        if (testd.x != 1.25) fail();
        if (testd.y != 1.75) fail();
        if (testd.z != 2.25) fail();

        Vec3i testi(2, 10, 20);
        int valuei = 2;
        testi /= valuei;
        if (testi.x != 1) fail();
        if (testi.y != 5) fail();
        if (testi.z != 10) fail();

    }

    Console::write_line("   Function: operator / (Type value)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        double valued = 2.0;
        testd = testd / valued;

        if (testd.x != 1.25) fail();
        if (testd.y != 1.75) fail();
        if (testd.z != 2.25) fail();

        Vec3i testi(2, 10, 20);
        int valuei = 2;
        testi = testi / valuei;
        if (testi.x != 1) fail();
        if (testi.y != 5) fail();
        if (testi.z != 10) fail();

    }

    Console::write_line("   Function: operator / (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd = testd / Vec3d(1.0, 2.5, 4.5);

        if (testd.x != 2.5) fail();
        if (testd.y != 1.4) fail();
        if (testd.z != 1.0) fail();

        Vec3i testi(2, 10, 20);
        testi = testi / Vec3i(1, 2, 3);
        if (testi.x != 2) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();

    }

    Console::write_line("   Function: operator = (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        testd = Vec3d(1.0, 2.0, 3.0);

        if (testd.x != 1.0) fail();
        if (testd.y != 2.0) fail();
        if (testd.z != 3.0) fail();

        Vec3i testi(2, 3, 4);
        testi = Vec3i(1, 2, 3);
        if (testi.x != 1) fail();
        if (testi.y != 2) fail();
        if (testi.z != 3) fail();

    }

    Console::write_line("   Function: operator == (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        if (testd == Vec3d(1.0, 2.0, 3.0)) fail();
        if (testd == Vec3d(2.5, 2.0, 3.0)) fail();
        if (testd == Vec3d(2.5, 3.5, 3.0)) fail();
        if (!(testd == Vec3d(2.5, 3.5, 4.5))) fail();

        Vec3i testi(2, 3, 4);
        if (testi == Vec3i(1, 2, 3)) fail();
        if (testi == Vec3i(2, 2, 3)) fail();
        if (testi == Vec3i(2, 3, 3)) fail();
        if (!(testi == Vec3i(2, 3, 4))) fail();
    }

    Console::write_line("   Function: operator != (const Vec3<Type>& vector)");
    {
        Vec3d testd(2.5, 3.5, 4.5);
        if (!(testd != Vec3d(1.0, 2.0, 3.0))) fail();
        if (!(testd != Vec3d(2.5, 2.0, 3.0))) fail();
        if (!(testd != Vec3d(2.5, 3.5, 3.0))) fail();
        if ((testd != Vec3d(2.5, 3.5, 4.5))) fail();

        Vec3i testi(2, 3, 4);
        if (!(testi != Vec3i(1, 2, 3))) fail();
        if (!(testi != Vec3i(2, 2, 3))) fail();
        if (!(testi != Vec3i(2, 3, 3))) fail();
        if ((testi != Vec3i(2, 3, 4))) fail();
    }

    Console::write_line("   Function: round()");
    {
        Vec3d testd(2.0, 2.5, -2.0);
        testd.round();

        if (testd.x != 2.0) fail();
        if (testd.y != 3.0) fail();
        if (testd.z != -2.0) fail();

        Vec3f testf(2.0f, 2.5f, -2.0f);
        testf.round();

        if (testf.x != 2.0f) fail();
        if (testf.y != 3.0f) fail();
        if (testf.z != -2.0f) fail();
    }

    Console::write_line("   Function: static round()");
    {
        Vec3d testd(2.0, 2.5, -2.0);
        Vec3d destd = Vec3d::round(testd);

        if (destd.x != 2.0) fail();
        if (destd.y != 3.0) fail();
        if (destd.z != -2.0) fail();

        Vec3f testf(2.0f, 2.5f, -2.0f);
        Vec3f destf = Vec3f::round(testf);

        if (destf.x != 2.0f) fail();
        if (destf.y != 3.0f) fail();
        if (destf.z != -2.0f) fail();
    }

    Console::write_line("   Function: Vec3<Type> operator * (const Mat3<Type>& matrix, const Vec3<Type>& v)");
    {
        /// Matrix is assumed to be in the Column-Major matrix format (opengl native)\n
        Mat3f matrix(1.0f, 2.0f, 3.0f,
                     4.0f, 5.0f, 6.0f,
                     7.0f, 8.0f, 9.0f);

        Vec3f vector(1.0f, 2.0f, 3.0f);
        Vec3f result = matrix * vector;

        if (result.x != ( (matrix[0 + 3*0] * vector.x) + (matrix[0 + 3*1] * vector.y) + (matrix[0 + 3*2] * vector.z) ) )
            fail();
        if (result.y != ( (matrix[1 + 3*0] * vector.x) + (matrix[1 + 3*1] * vector.y) + (matrix[1 + 3*2] * vector.z) ) )
            fail();
        if (result.z != ( (matrix[2 + 3*0] * vector.x) + (matrix[2 + 3*1] * vector.y) + (matrix[2 + 3*2] * vector.z) ) )
            fail();

    }
}
示例#14
0
void TestApp::test_vector4(void)
{
    Console::write_line(" Header: cl_vector.h");
    Console::write_line("  Class: Vec4");

    Console::write_line("   Function: distance3()");
    {
        Vec4d test_a(2.0,3.0,4.0,5.0);
        Vec4d test_b(3.0,4.0,5.0,6.0);

        if (test_a.distance3(test_b) != sqrt(1.0 + 1.0 + 1.0 ))  fail();
    }

    Console::write_line("   Function: distance4()");
    {
        Vec4d test_a(2.0,3.0,4.0,5.0);
        Vec4d test_b(3.0,4.0,5.0,6.0);

        if (test_a.distance4(test_b) != sqrt(1.0 + 1.0 + 1.0 + 1.0 ))  fail();
    }

    Console::write_line("   Function: length3()");
    {
        Vec4d testi(3.0,4.0,5.0,6.0);
        if (testi.length3() != sqrt(50.0 ))  fail();
    }

    Console::write_line("   Function: length4()");
    {
        Vec4d testi(3.0,4.0,5.0,6.0);
        if (testi.length4() != sqrt(86.0 ))  fail();
    }

    Console::write_line("   Function: normalize3()");
    {
        Vec4d testi(3.0,4.0,5.0,6.0);
        testi.normalize3();
        if (testi !=  Vec4d(3.0/sqrt(50.0), 4.0/sqrt(50.0), 5.0/sqrt(50.0), 6.0))  fail();
    }

    Console::write_line("   Function: static normalize3()");
    {
        Vec4d testi(3.0,4.0,5.0,6.0);
        if (Vec4d::normalize3(testi) !=  Vec4d(3.0/sqrt(50.0), 4.0/sqrt(50.0), 5.0/sqrt(50.0), 6.0))  fail();
    }

    Console::write_line("   Function: dot3()");
    {
        Vec4d test_a(3.0,4.0,5.0,6.0);
        Vec4d test_b(13.0,14.0,15.0,16.0);
        if (test_a.dot3(test_b) != ((3.0 * 13.0)+ (4.0*14.0) + (5.0 * 15.0)))  fail();
    }

    Console::write_line("   Function: dot4()");
    {
        Vec4d test_a(3.0,4.0,5.0,6.0);
        Vec4d test_b(13.0,14.0,15.0,16.0);
        if (test_a.dot4(test_b) != ((3.0 * 13.0)+ (4.0*14.0) + (5.0 * 15.0) + (6.0 * 16.0)))  fail();
    }

    Console::write_line("   Function: normalize4()");
    {
        Vec4d testi(3.0,4.0,5.0,6.0);
        testi.normalize4();
        if (testi !=  Vec4d(3.0/sqrt(86.0), 4.0/sqrt(86.0), 5.0/sqrt(86.0), 6.0/sqrt(86.0)))  fail();
    }

    Console::write_line("   Function: static normalize4()");
    {
        Vec4d testi(3.0,4.0,5.0,6.0);
        if (Vec4d::normalize4(testi) !=  Vec4d(3.0/sqrt(86.0), 4.0/sqrt(86.0), 5.0/sqrt(86.0), 6.0/sqrt(86.0)))  fail();
    }

    Console::write_line("   Function: operator += (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd += Vec4d(1.0, 2.0, 3.0, 4.0);

        if (testd.x != 3.5) fail();
        if (testd.y != 5.5) fail();
        if (testd.z != 7.5) fail();
        if (testd.w != 9.5) fail();

        Vec4i testi(2, 3, 4, 5);
        testi += Vec4i(1, 2, 3, 4);
        if (testi.x != 3) fail();
        if (testi.y != 5) fail();
        if (testi.z != 7) fail();
        if (testi.w != 9) fail();

    }

    Console::write_line("   Function: operator += ( Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd += valued;

        if (testd.x != 4.5) fail();
        if (testd.y != 5.5) fail();
        if (testd.z != 6.5) fail();
        if (testd.w != 7.5) fail();

        Vec4i testi(2, 3, 4, 5);
        int valuei = 2;
        testi += valuei;
        if (testi.x != 4) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();
        if (testi.w != 7) fail();

    }

    Console::write_line("   Function: operator + (Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd = testd + valued;

        if (testd.x != 4.5) fail();
        if (testd.y != 5.5) fail();
        if (testd.z != 6.5) fail();
        if (testd.w != 7.5) fail();

        Vec4i testi(2, 3, 4, 5);
        int valuei = 2;
        testi = testi + valuei;
        if (testi.x != 4) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();
        if (testi.w != 7) fail();

    }

    Console::write_line("   Function: operator + (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd = testd + Vec4d(1.5, 2.5, 3.5, 4.5);

        if (testd.x != 4.0) fail();
        if (testd.y != 6.0) fail();
        if (testd.z != 8.0) fail();
        if (testd.w != 10.0) fail();

        Vec4i testi(2, 3, 4, 5);
        testi = testi + Vec4i(1, 2, 3, 4);
        if (testi.x != 3) fail();
        if (testi.y != 5) fail();
        if (testi.z != 7) fail();
        if (testi.w != 9) fail();

    }

    Console::write_line("   Function: operator -= (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd -= Vec4d(1.0, 2.0, 3.0, 4.0);

        if (testd.x != 1.5) fail();
        if (testd.y != 1.5) fail();
        if (testd.z != 1.5) fail();
        if (testd.w != 1.5) fail();

        Vec4i testi(2, 3, 4, 5);
        testi -= Vec4i(1, 2, 3, 4);
        if (testi.x != 1) fail();
        if (testi.y != 1) fail();
        if (testi.z != 1) fail();
        if (testi.w != 1) fail();

    }

    Console::write_line("   Function: operator -= ( Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd -= valued;

        if (testd.x != 0.5) fail();
        if (testd.y != 1.5) fail();
        if (testd.z != 2.5) fail();
        if (testd.w != 3.5) fail();

        Vec4i testi(2, 3, 4, 5);
        int valuei = 2;
        testi -= valuei;
        if (testi.x != 0) fail();
        if (testi.y != 1) fail();
        if (testi.z != 2) fail();
        if (testi.w != 3) fail();

    }

    Console::write_line("   Function: operator - (Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd = testd - valued;

        if (testd.x != 0.5) fail();
        if (testd.y != 1.5) fail();
        if (testd.z != 2.5) fail();
        if (testd.w != 3.5) fail();

        Vec4i testi(2, 3, 4, 5);
        int valuei = 2;
        testi = testi - valuei;
        if (testi.x != 0) fail();
        if (testi.y != 1) fail();
        if (testi.z != 2) fail();
        if (testi.w != 3) fail();

    }

    Console::write_line("   Function: operator - (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd = testd - Vec4d(1.5, 2.5, 3.5, 4.5);

        if (testd.x != 1.0) fail();
        if (testd.y != 1.0) fail();
        if (testd.z != 1.0) fail();
        if (testd.w != 1.0) fail();

        Vec4i testi(2, 3, 4, 5);
        testi = testi - Vec4i(1, 2, 3, 4);
        if (testi.x != 1) fail();
        if (testi.y != 1) fail();
        if (testi.z != 1) fail();
        if (testi.w != 1) fail();

    }

    Console::write_line("   Function: operator *= (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd *= Vec4d(1.0, 2.0, 3.0, 4.0);

        if (testd.x != 2.5) fail();
        if (testd.y != 7.0) fail();
        if (testd.z != 13.5) fail();
        if (testd.w != 22.0) fail();

        Vec4i testi(2, 3, 4, 5);
        testi *= Vec4i(1, 2, 3, 4);
        if (testi.x != 2) fail();
        if (testi.y != 6) fail();
        if (testi.z != 12) fail();
        if (testi.w != 20) fail();

    }

    Console::write_line("   Function: operator *= ( Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd *= valued;

        if (testd.x != 5.0) fail();
        if (testd.y != 7.0) fail();
        if (testd.z != 9.0) fail();
        if (testd.w != 11.0) fail();

        Vec4i testi(2, 3, 4, 5);
        int valuei = 2;
        testi *= valuei;
        if (testi.x != 4) fail();
        if (testi.y != 6) fail();
        if (testi.z != 8) fail();
        if (testi.w != 10) fail();

    }

    Console::write_line("   Function: operator * (Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd = testd * valued;

        if (testd.x != 5.0) fail();
        if (testd.y != 7.0) fail();
        if (testd.z != 9.0) fail();
        if (testd.w != 11.0) fail();

        Vec4i testi(2, 3, 4, 5);
        int valuei = 2;
        testi = testi * valuei;
        if (testi.x != 4) fail();
        if (testi.y != 6) fail();
        if (testi.z != 8) fail();
        if (testi.w != 10) fail();

    }

    Console::write_line("   Function: operator * (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd = testd * Vec4d(1.5, 2.5, 3.5, 4.5);

        if (testd.x != 3.75) fail();
        if (testd.y != 8.75) fail();
        if (testd.z != 15.75) fail();
        if (testd.w != 24.75) fail();

        Vec4i testi(2, 3, 4, 5);
        testi = testi * Vec4i(1, 2, 3, 4);
        if (testi.x != 2) fail();
        if (testi.y != 6) fail();
        if (testi.z != 12) fail();
        if (testi.w != 20) fail();

    }

    Console::write_line("   Function: operator /= (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd /= Vec4d(1.0, 2.0, 3.0, 4.0);

        if (testd.x != 2.5) fail();
        if (testd.y != 1.75) fail();
        if (testd.z != 1.5) fail();
        if (testd.w != 1.375) fail();

        Vec4i testi(2, 10, 20, 5);
        testi /= Vec4i(1, 2, 3, 4);
        if (testi.x != 2) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();
        if (testi.w != 1) fail();

    }

    Console::write_line("   Function: operator /= ( Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd /= valued;

        if (testd.x != 1.25) fail();
        if (testd.y != 1.75) fail();
        if (testd.z != 2.25) fail();
        if (testd.w != 2.75) fail();

        Vec4i testi(2, 10, 20, 5);
        int valuei = 2;
        testi /= valuei;
        if (testi.x != 1) fail();
        if (testi.y != 5) fail();
        if (testi.z != 10) fail();
        if (testi.w != 2) fail();

    }

    Console::write_line("   Function: operator / (Type value)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        double valued = 2.0;
        testd = testd / valued;

        if (testd.x != 1.25) fail();
        if (testd.y != 1.75) fail();
        if (testd.z != 2.25) fail();
        if (testd.w != 2.75) fail();

        Vec4i testi(2, 10, 20, 5);
        int valuei = 2;
        testi = testi / valuei;
        if (testi.x != 1) fail();
        if (testi.y != 5) fail();
        if (testi.z != 10) fail();
        if (testi.w != 2) fail();

    }

    Console::write_line("   Function: operator / (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 10.0);
        testd = testd / Vec4d(1.0, 2.5, 4.5, 2.0);

        if (testd.x != 2.5) fail();
        if (testd.y != 1.4) fail();
        if (testd.z != 1.0) fail();
        if (testd.w != 5.0) fail();

        Vec4i testi(2, 10, 20, 5);
        testi = testi / Vec4i(1, 2, 3, 4);
        if (testi.x != 2) fail();
        if (testi.y != 5) fail();
        if (testi.z != 6) fail();
        if (testi.w != 1) fail();

    }

    Console::write_line("   Function: operator = (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        testd = Vec4d(1.0, 2.0, 3.0, 4.0);

        if (testd.x != 1.0) fail();
        if (testd.y != 2.0) fail();
        if (testd.z != 3.0) fail();
        if (testd.w != 4.0) fail();

        Vec4i testi(2, 3, 4, 5);
        testi = Vec4i(1, 2, 3, 4);
        if (testi.x != 1) fail();
        if (testi.y != 2) fail();
        if (testi.z != 3) fail();
        if (testi.w != 4) fail();

    }

    Console::write_line("   Function: operator == (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        if (testd == Vec4d(1.0, 2.0, 3.0, 4.0)) fail();
        if (testd == Vec4d(2.5, 2.0, 3.0, 4.0)) fail();
        if (testd == Vec4d(2.5, 3.5, 3.0, 4.0)) fail();
        if (testd == Vec4d(2.5, 3.5, 4.5, 4.0)) fail();
        if (!(testd == Vec4d(2.5, 3.5, 4.5, 5.5))) fail();

        Vec4i testi(2, 3, 4, 5);
        if (testi == Vec4i(1, 2, 3, 4)) fail();
        if (testi == Vec4i(2, 2, 3, 4)) fail();
        if (testi == Vec4i(2, 3, 3, 4)) fail();
        if (testi == Vec4i(2, 3, 4, 4)) fail();
        if (!(testi == Vec4i(2, 3, 4, 5))) fail();
    }

    Console::write_line("   Function: operator != (const Vec4<Type>& vector)");
    {
        Vec4d testd(2.5, 3.5, 4.5, 5.5);
        if (!(testd != Vec4d(1.0, 2.0, 3.0, 4.0))) fail();
        if (!(testd != Vec4d(2.5, 2.0, 3.0, 4.0))) fail();
        if (!(testd != Vec4d(2.5, 3.5, 3.0, 4.0))) fail();
        if (!(testd != Vec4d(2.5, 3.5, 4.5, 4.0))) fail();
        if ((testd != Vec4d(2.5, 3.5, 4.5, 5.5))) fail();

        Vec4i testi(2, 3, 4, 5);
        if (!(testi != Vec4i(1, 2, 3, 4))) fail();
        if (!(testi != Vec4i(2, 2, 3, 4))) fail();
        if (!(testi != Vec4i(2, 3, 3, 4))) fail();
        if (!(testi != Vec4i(2, 3, 4, 4))) fail();
        if ((testi != Vec4i(2, 3, 4, 5))) fail();
    }

    Console::write_line("   Function: round()");
    {
        Vec4d testd(2.0, 2.5, -2.0, -2.5);
        testd.round();

        if (testd.x != 2.0) fail();
        if (testd.y != 3.0) fail();
        if (testd.z != -2.0) fail();
        if (testd.w != -2.0) fail();

        Vec4f testf(2.0f, 2.5f, -2.0f, -2.9f);
        testf.round();

        if (testf.x != 2.0f) fail();
        if (testf.y != 3.0f) fail();
        if (testf.z != -2.0f) fail();
        if (testf.w != -3.0f) fail();
    }

    Console::write_line("   Function: static round()");
    {
        Vec4d testd(2.0, 2.5, -2.0, -2.5);
        Vec4d destd = Vec4d::round(testd);

        if (destd.x != 2.0) fail();
        if (destd.y != 3.0) fail();
        if (destd.z != -2.0) fail();
        if (destd.w != -2.0) fail();

        Vec4f testf(2.0f, 2.5f, -2.0f, -2.9f);
        Vec4f destf = Vec4f::round(testf);

        if (destf.x != 2.0f) fail();
        if (destf.y != 3.0f) fail();
        if (destf.z != -2.0f) fail();
        if (destf.w != -3.0f) fail();
    }
}
示例#15
0
void TestApp::test_matrix_mat4()
{
	Console::write_line("  Class: Mat4");

	Console::write_line("   Function: inverse()");
	{

		Mat4f test_src = Mat4f::rotate((Angle(30, angle_degrees)), 1.0, 0.0, 0.0, true);
		Mat4f test_inv;
		Mat4f test_dest;
		Mat4f test_ident = Mat4f::identity();

		test_dest = test_src;
		test_dest.inverse();
		test_dest = test_dest * test_src;

		if (test_ident != test_dest) fail();

	}

	static int test_a_values[] = {3, 1, 2, 4, 5 ,6, 4, 2, 1, 4, 6, 7, 6, 3, 7, 2};
	static int test_b_values[] = {4, 7, 2, 5, 3, 5, 2, 9, 3, 3, 6, 9, 2, 4, 6, 2};

	Mat4i test_a(test_a_values);
	Mat4i test_b(test_b_values);

	Mat4f test_c(test_a);
	Mat4f test_c_scaled(test_c);

	{
		float x = 2.0f;
		float y = 3.0f;
		float z = 4.0f;

		test_c_scaled[0 + 4 * 0] *= x;
		test_c_scaled[0 + 4 * 1] *= y;
		test_c_scaled[0 + 4 * 2] *= z;
		test_c_scaled[1 + 4 * 0] *= x;
		test_c_scaled[1 + 4 * 1] *= y;
		test_c_scaled[1 + 4 * 2] *= z;
		test_c_scaled[2 + 4 * 0] *= x;
		test_c_scaled[2 + 4 * 1] *= y;
		test_c_scaled[2 + 4 * 2] *= z;
		test_c_scaled[3 + 4 * 0] *= x;
		test_c_scaled[3 + 4 * 1] *= y;
		test_c_scaled[3 + 4 * 2] *= z;
	}

	Console::write_line("   Function: add() and operator");
	{
		int answer_values[] = {7, 8, 4, 9, 8, 11, 6, 11, 4, 7, 12, 16, 8, 7, 13, 4};
		Mat4i answer(answer_values);

		Mat4i result = test_a + test_b;
		if (result != answer) fail();

		result = Mat4i::add(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: subtract() and operator");
	{
		int answer_values[] = {-1, -6, 0, -1, 2, 1, 2, -7, -2, 1, 0, -2, 4, -1, 1, 0};
		Mat4i answer(answer_values);

		Mat4i result = test_a - test_b;
		if (result != answer) fail();

		result = Mat4i::subtract(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: translate()");
	{
		int answer_values[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 3, 4, 1};
		Mat4i answer(answer_values);

		Mat4i result = Mat4i::translate(2, 3, 4);
		if (result != answer) fail();
	}

	Console::write_line("   Function: translate_self() (int)");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::translate(2, 3, 4);

		Mat4i result2 = test_a;
		result2.translate_self(2,3,4);

		if (result != result2) fail();
	}

	Console::write_line("   Function: translate_self() (float)");
	{
		Mat4f answer(test_a);

		Mat4f result(test_a);
		result = result * Mat4f::translate(2, 3, 4);

		Mat4f result2(test_a);
		result2.translate_self(2, 3, 4);

		if (!result.is_equal(result2, 0.00001f))
			fail();
	}

	Console::write_line("   Function: scale_self()");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::scale(2, 3, 4);

		Mat4i result2 = test_a;
		result2.scale_self(2,3,4);

		if (result != result2) fail();

		Mat4f test = test_c;
		test.scale_self(2.0f, 3.0f, 4.0f);

		if (!test.is_equal(test_c_scaled, 0.00001f))
			fail();
	}

	Console::write_line("   Function: rotate (using euler angles)");
	{
		Mat4f mv = Mat4f::identity();
		mv = mv * Mat4f::rotate(Angle(30.0f, angle_degrees), 0.0f, 0.0f, 1.0f, false);
		mv = mv * Mat4f::rotate(Angle(10.0f, angle_degrees), 1.0f, 0.0f, 0.0f, false);
		mv = mv * Mat4f::rotate(Angle(20.0f, angle_degrees), 0.0f, 1.0f, 0.0f, false);

		Mat4f test_matrix;
		test_matrix = Mat4f::rotate(Angle(10.0f, angle_degrees), Angle(20.0f, angle_degrees), Angle(30.0f, angle_degrees), order_YXZ);
		if (!test_matrix.is_equal(mv, 0.00001f))
			fail();

	}

	Console::write_line("   Function: rotate (using euler angles) and get_euler");
	{
		test_rotate_and_get_euler(order_XYZ);
		test_rotate_and_get_euler(order_XZY);
		test_rotate_and_get_euler(order_YZX);
		test_rotate_and_get_euler(order_YXZ);
		test_rotate_and_get_euler(order_ZXY);
		test_rotate_and_get_euler(order_ZYX);
	}

	Console::write_line("   Function: transpose() (float)");
	{
		Mat4f original(test_a);

		Mat4f transposed_matrix;
	
		transposed_matrix[0] = original[0];
		transposed_matrix[1] = original[4];
		transposed_matrix[2] = original[8];
		transposed_matrix[3] = original[12];
		transposed_matrix[4] = original[1];
		transposed_matrix[5] = original[5];
		transposed_matrix[6] = original[9];
		transposed_matrix[7] = original[13];
		transposed_matrix[8] = original[2];
		transposed_matrix[9] = original[6];
		transposed_matrix[10] = original[10];
		transposed_matrix[11] = original[14];
		transposed_matrix[12] = original[3];
		transposed_matrix[13] = original[7];
		transposed_matrix[14] = original[11];
		transposed_matrix[15] = original[15];

		Mat4f test = original;
		test.transpose();

		if (!test.is_equal(transposed_matrix, 0.00001f))
			fail();
	}
}
示例#16
0
void TestApp::test_matrix_mat4()
{
	Console::write_line("  Class: Mat4");

	Console::write_line("   Function: inverse()");
	{

		Mat4f test_src = Mat4f::rotate((Angle(30, angle_degrees)), 1.0, 0.0, 0.0, true);
		Mat4f test_inv;
		Mat4f test_dest;
		Mat4f test_ident = Mat4f::identity();

		test_dest = test_src;
		test_dest.inverse();
		test_dest = test_dest * test_src;

		if (test_ident != test_dest) fail();

	}

	static int test_a_values[] = {3, 1, 2, 4, 5 ,6, 4, 2, 1, 4, 6, 7, 6, 3, 7, 2};
	static int test_b_values[] = {4, 7, 2, 5, 3, 5, 2, 9, 3, 3, 6, 9, 2, 4, 6, 2};

	Mat4i test_a(test_a_values);
	Mat4i test_b(test_b_values);

	Console::write_line("   Function: add() and operator");
	{
		int answer_values[] = {7, 8, 4, 9, 8, 11, 6, 11, 4, 7, 12, 16, 8, 7, 13, 4};
		Mat4i answer(answer_values);

		Mat4i result = test_a + test_b;
		if (result != answer) fail();

		result = Mat4i::add(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: subtract() and operator");
	{
		int answer_values[] = {-1, -6, 0, -1, 2, 1, 2, -7, -2, 1, 0, -2, 4, -1, 1, 0};
		Mat4i answer(answer_values);

		Mat4i result = test_a - test_b;
		if (result != answer) fail();

		result = Mat4i::subtract(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: translate()");
	{
		int answer_values[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 3, 4, 1};
		Mat4i answer(answer_values);

		Mat4i result = Mat4i::translate(2, 3, 4);
		if (result != answer) fail();
	}

	Console::write_line("   Function: translate_self()");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::translate(2, 3, 4);

		Mat4i result2 = test_a;
		result2.translate_self(2,3,4);

		if (result != result2) fail();
	}

	Console::write_line("   Function: scale_self()");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::scale(2, 3, 4);

		Mat4i result2 = test_a;
		result2.scale_self(2,3,4);

		if (result != result2) fail();
	}

	Console::write_line("   Function: rotate (using euler angles) and get_euler");
	{
		Angle angle_x(20, angle_degrees);
		Angle angle_y(30, angle_degrees);
		Angle angle_z(40, angle_degrees);

		Mat4f test_matrix;
		test_matrix = Mat4f::rotate(angle_x, angle_y, angle_z, order_YXZ);

		Vec3f angles = test_matrix.get_euler(order_YXZ);

		check_float(angles.x, angle_x.to_radians());
		check_float(angles.y, angle_y.to_radians());
		check_float(angles.z, angle_z.to_radians());
	}
}