1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 18:32:44 +01:00

Make unit tests work again, fixing tests & code

This commit is contained in:
Daniel Evans 2016-05-02 17:38:04 +01:00
parent 9bc535d243
commit e7faa60926
8 changed files with 28 additions and 16 deletions

View File

@ -41,6 +41,8 @@ void Animator::tick(float dt)
} }
} }
state.time = state.time + dt;
float animTime = state.time; float animTime = state.time;
if (! state.repeat) if (! state.repeat)
{ {
@ -84,7 +86,6 @@ void Animator::tick(float dt)
blendFrames[b.second.frameIndex] = xform; blendFrames[b.second.frameIndex] = xform;
#endif #endif
} }
state.time = state.time + dt;
} }
for (auto& p : blendFrames) for (auto& p : blendFrames)

View File

@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(test_matrix)
} }
}; };
animator.playAnimation(0, &animation, 1.f, true); animator.playAnimation(0, &animation, 1.f, false);
animator.tick(0.0f); animator.tick(0.0f);

View File

@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(test_create)
BOOST_AUTO_TEST_CASE(test_activities) BOOST_AUTO_TEST_CASE(test_activities)
{ {
{ {
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f}); auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 225.6f});
BOOST_REQUIRE( character != nullptr ); BOOST_REQUIRE( character != nullptr );

View File

@ -45,13 +45,15 @@ public:
Global() { Global() {
wnd.create(sf::VideoMode(640, 360), "Testing"); wnd.create(sf::VideoMode(640, 360), "Testing");
d = new GameData(&log, &work, getGamePath()); d = new GameData(&log, &work, getGamePath());
d->loadIMG("/models/gta3");
d->loadIMG("/anim/cuts");
d->load();
e = new GameWorld(&log, &work, d); e = new GameWorld(&log, &work, d);
s = new GameState; s = new GameState;
e->state = s; e->state = s;
e->data->loadIMG("/models/gta3");
e->data->loadIMG("/anim/cuts");
e->data->load();
for(std::map<std::string, std::string>::iterator it = e->data->ideLocations.begin(); for(std::map<std::string, std::string>::iterator it = e->data->ideLocations.begin();
it != e->data->ideLocations.end(); it != e->data->ideLocations.end();
++it) { ++it) {

View File

@ -11,18 +11,23 @@ BOOST_AUTO_TEST_CASE(test_character_inventory)
BOOST_REQUIRE( character != nullptr ); BOOST_REQUIRE( character != nullptr );
auto item = Global::get().e->getInventoryItem(4); auto item = Global::get().e->getInventoryItem(4);
auto fist = Global::get().e->getInventoryItem(0);
BOOST_REQUIRE(item != nullptr); BOOST_REQUIRE(item != nullptr);
BOOST_REQUIRE(fist != nullptr );
BOOST_CHECK_NE( fist, item );
character->addToInventory(item); character->addToInventory(item);
BOOST_CHECK_EQUAL( character->getActiveItem(), fist );
character->setActiveItem( item->getInventorySlot() ); character->setActiveItem( item->getInventorySlot() );
BOOST_CHECK_EQUAL( character->getActiveItem(), item ); BOOST_CHECK_EQUAL( character->getActiveItem(), item );
character->removeFromInventory( item->getInventorySlot() ); character->removeFromInventory( item->getInventorySlot() );
BOOST_CHECK_EQUAL( character->getActiveItem(), nullptr ); BOOST_CHECK_EQUAL( character->getActiveItem(), fist );
Global::get().e->destroyObject(character); Global::get().e->destroyObject(character);
} }

View File

@ -11,13 +11,17 @@ BOOST_AUTO_TEST_CASE(frustum_test_visible)
f.update(f.projection()); f.update(f.projection());
BOOST_CHECK( f.intersects({10.f, 0.f, 0.f}, 1.f ) ); BOOST_CHECK( f.intersects({10.f, 0.f,-10.f}, 1.f ) );
BOOST_CHECK(!f.intersects({-10.f, 0.f, 0.f}, 1.f ) ); BOOST_CHECK(!f.intersects({ 0.f, 0.f, 10.f}, 1.f ) );
BOOST_CHECK(!f.intersects({0.f, 10.f, 0.f}, 1.f ) ); BOOST_CHECK(!f.intersects({0.f, 10.f, 0.f}, 1.f ) );
BOOST_CHECK(!f.intersects({0.f,-10.f, 0.f}, 1.f ) ); BOOST_CHECK(!f.intersects({0.f,-10.f, 0.f}, 1.f ) );
BOOST_CHECK( f.intersects({10.f, 10.f, 0.f}, 1.f ) ); BOOST_CHECK(!f.intersects({ 10.f, 0.f, 0.f}, 1.f ) );
BOOST_CHECK(!f.intersects({-10.f, 0.f, 0.f}, 1.f ) );
BOOST_CHECK( f.intersects({ 10.f, 0.f,-10.f}, 1.f ) );
BOOST_CHECK( f.intersects({-10.f, 0.f,-10.f}, 1.f ) );
} }
} }

View File

@ -76,13 +76,12 @@ BOOST_AUTO_TEST_CASE(test_available_nodes)
{-10.f, 0.f, 0.f } {-10.f, 0.f, 0.f }
}; };
BOOST_REQUIRE(expected.size() == 3);
BOOST_ASSERT( expected.size() == open.size() ); BOOST_ASSERT( expected.size() == open.size() );
auto left = open.begin(); for (auto& v : expected) {
auto right = expected.begin(); BOOST_CHECK(std::find_if(open.begin(), open.end(),
for ( ; left != open.end() && right != expected.end(); ++left, ++right ) [v](AIGraphNode* n) { return n->position == v; }) != open.end());
{
BOOST_CHECK( ! ( *left != *right ) );
} }
} }

View File

@ -51,7 +51,8 @@ BOOST_AUTO_TEST_CASE(TestProjectile)
projectile->tick(0.016f); projectile->tick(0.016f);
} }
BOOST_CHECK_LT( glm::distance(character->getPosition(), projectile->getPosition()), 1.f ); BOOST_CHECK_LT( glm::distance(character->getPosition(), projectile->getPosition()), 10.f );
BOOST_CHECK_LT( glm::distance(character->getPosition(), projectile->getPosition()), 5.f );
// Grenade should have dentonated by this point // Grenade should have dentonated by this point
BOOST_CHECK( character->getCurrentState().health < 100.f ); BOOST_CHECK( character->getCurrentState().health < 100.f );