Add common VECTOR2 test cases

This commit is contained in:
Seth Hillbrand 2024-06-10 15:12:57 -07:00
parent 439c25fca9
commit 37191720ca
1 changed files with 71 additions and 0 deletions

View File

@ -67,4 +67,75 @@ BOOST_AUTO_TEST_CASE( test_resize, *boost::unit_test::tolerance( 0.000001 ) )
BOOST_CHECK( v5.Resize( 100 ) == VECTOR2I( -71, -71 ) ); BOOST_CHECK( v5.Resize( 100 ) == VECTOR2I( -71, -71 ) );
} }
BOOST_AUTO_TEST_CASE( test_casting )
{
VECTOR2I vint( 4, 3 );
VECTOR2D vdouble( 4.0, 3.0 );
VECTOR2L vlong( 4, 3 );
VECTOR2<float> vfloat( 4.0f, 3.0f );
VECTOR2<unsigned> vunsigned( 4, 3 );
BOOST_CHECK( vint == VECTOR2I( vdouble ) );
BOOST_CHECK( vint == VECTOR2I( vlong ) );
BOOST_CHECK( vint == VECTOR2I( vfloat ) );
BOOST_CHECK( vint == VECTOR2I( vunsigned ) );
BOOST_CHECK( vdouble == VECTOR2D( vint ) );
BOOST_CHECK( vdouble == VECTOR2D( vlong ) );
BOOST_CHECK( vdouble == VECTOR2D( vfloat ) );
BOOST_CHECK( vdouble == VECTOR2D( vunsigned ) );
BOOST_CHECK( vlong == VECTOR2L( vint ) );
BOOST_CHECK( vlong == VECTOR2L( vdouble ) );
BOOST_CHECK( vlong == VECTOR2L( vfloat ) );
BOOST_CHECK( vlong == VECTOR2L( vunsigned ) );
BOOST_CHECK( vfloat == VECTOR2<float>( vint ) );
BOOST_CHECK( vfloat == VECTOR2<float>( vdouble ) );
BOOST_CHECK( vfloat == VECTOR2<float>( vlong ) );
BOOST_CHECK( vfloat == VECTOR2<float>( vunsigned ) );
BOOST_CHECK( vunsigned == VECTOR2<unsigned>( vint ) );
BOOST_CHECK( vunsigned == VECTOR2<unsigned>( vdouble ) );
BOOST_CHECK( vunsigned == VECTOR2<unsigned>( vlong ) );
BOOST_CHECK( vunsigned == VECTOR2<unsigned>( vfloat ) );
// Check that negative values are handled correctly
vint = vint - 1;
vdouble = vdouble - 1;
vlong = vlong - 1;
vfloat = vfloat - 1;
vunsigned = vunsigned - 1;
BOOST_CHECK( vint == VECTOR2I( 3, 2 ) );
BOOST_CHECK( vdouble == VECTOR2D( 3.0, 2.0 ) );
BOOST_CHECK( vlong == VECTOR2L( 3, 2 ) );
BOOST_CHECK( vfloat == VECTOR2<float>( 3.0f, 2.0f ) );
BOOST_CHECK( vunsigned == VECTOR2<unsigned>( 3, 2 ) );
// Check that negative initial values are handled correctly
vint = VECTOR2I( -4, -3 );
vdouble = VECTOR2D( -4.0, -3.0 );
vlong = VECTOR2L( -4, -3 );
vfloat = VECTOR2<float>( -4.0f, -3.0f );
vint = vint - 1;
vdouble = vdouble - 1;
vlong = vlong - 1;
vfloat = vfloat - 1;
BOOST_CHECK( vint == VECTOR2I( -5, -4 ) );
BOOST_CHECK( vdouble == VECTOR2D( -5.0, -4.0 ) );
BOOST_CHECK( vlong == VECTOR2L( -5, -4 ) );
BOOST_CHECK( vfloat == VECTOR2<float>( -5.0f, -4.0f ) );
auto add = vint + vdouble;
BOOST_CHECK( add == VECTOR2D( -10.0, -8.0 ) );
auto sub = vint - 2 * vlong;
BOOST_CHECK( sub.x == 5 );
BOOST_CHECK( sub.y == 4 );
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()