void enum_() { testtype tv0 = testtypes::foo; tv0 == testtypes::foo or TESTFAIL; tv0 != testtypes::bar or TESTFAIL; testtype tv1 = testtypes::bar; tv0 == tv1 and TESTFAIL; // "default value" testtype tv2; // the enum doesn't have 12 members; thus, this defaults to the default value. testtype tv3; tv2 == tv3 or TESTFAIL; FString fstr; fstr << tv0; TESTEQUALS(fstr.buffer, "openage::util::tests::testtypes::foo"); fstr.reset(); fstr << tv2; TESTEQUALS(fstr.buffer, "<default enum value>"); TESTEQUALS(tv0.get()->stuff, "some text"); TESTEQUALS(tv0->stuff, "some text"); TESTEQUALS(tv2->stuff, ""); }
void vector() { { // tests in 2 dimensions. // we want to be able to reuse the variable names later. const Vector<2> a(1.0, 2.0); const Vector<2> b(3.0, 4.0); Vector<2> c; c = a + b; TESTEQUALS(c[0], 4.0); TESTEQUALS(c[1], 6.0); c = a - b; TESTEQUALS(c[0], -2.0); TESTEQUALS(c[1], -2.0); c = 5 * a; TESTEQUALS(c[0], 5.0); TESTEQUALS(c[1], 10.0); // division by 8 should be precise c = a / 8; TESTEQUALS(c[0], 0.125); TESTEQUALS(c[1], 0.25); TESTEQUALS(a.dot_product(b), 11); c = b; TESTEQUALS(c.norm(), 5); c.normalize(); TESTEQUALS_FLOAT(c.norm(), 1, 1e-7); } { // test for the cross_product const Vector<3> a(1.0, 2.0, 3.0); const Vector<3> b(4.0, 5.0, 6.0); Vector<3> c = a.cross_product(b); TESTEQUALS(c[0], -3.0); TESTEQUALS(c[1], 6.0); TESTEQUALS(c[2], -3.0); } }
/** * test method for the base CoordXY* classes. */ void coord() { // test comparision TESTEQUALS(TestCoordsAbsolute(3, 4) == TestCoordsAbsolute(3, 4), true); TESTEQUALS(TestCoordsAbsolute(3, 4) != TestCoordsAbsolute(3, 4), false); TESTEQUALS(TestCoordsAbsolute(3, 4) == TestCoordsAbsolute(3, 5), false); TESTEQUALS(TestCoordsAbsolute(3, 4) == TestCoordsAbsolute(4, 4), false); TESTEQUALS(TestCoordsAbsolute(3, 4) != TestCoordsAbsolute(3, 5), true); TESTEQUALS(TestCoordsRelative(3, 4) == TestCoordsRelative(3, 4), true); TESTEQUALS(TestCoordsRelative(3, 4) != TestCoordsRelative(3, 4), false); TESTEQUALS(TestCoordsRelative(3, 4) == TestCoordsRelative(3, 5), false); TESTEQUALS(TestCoordsRelative(3, 4) == TestCoordsRelative(4, 4), false); TESTEQUALS(TestCoordsRelative(3, 4) != TestCoordsRelative(3, 5), true); // test copy constructor / assignment operator TestCoordsAbsolute a0(1, 2); TestCoordsRelative r0(3, 4); TESTEQUALS(a0, TestCoordsAbsolute(1, 2)); TESTEQUALS(r0, TestCoordsRelative(3, 4)); TestCoordsAbsolute a1{a0}; TestCoordsRelative r1{r0}; TESTEQUALS(a0, a1); TESTEQUALS(r0, r1); a1 = a0; r1 = r0; TESTEQUALS(a0, a1); TESTEQUALS(r0, r1); // test unary +/- TESTEQUALS(-r0, TestCoordsRelative(-3, -4)); TESTEQUALS(+r0, TestCoordsRelative(3, 4)); // test addition TESTEQUALS(r0 + r0, TestCoordsRelative(6, 8)); TESTEQUALS(a0 + r0, TestCoordsAbsolute(4, 6)); TESTEQUALS(r0 + a0, TestCoordsAbsolute(4, 6)); // test scalar multiplication and division TESTEQUALS(r0 * 3, TestCoordsRelative(9, 12)); TESTEQUALS(r0 / 3, TestCoordsRelative(1, 1)); // test string representation util::FString s; s << TestCoordsAbsolute(1, 2); TESTEQUALS(std::string(s), "[x: 1, y: 2]"); s.reset(); s << TestCoordsRelative(3, 4); TESTEQUALS(std::string(s), "(x: 3, y: 4)"); }