void Project2Test::test_MGMap_calculateOneStepPath() { // Setup MGMap map; map.init(10, 10, 16, 16, 640, 480); // Trigger std::list<MGPathItem> path = map.calculatePath(MGFBASICPATH1, 3, 3, 4, 4); // Verify ASSERT_EQ(path.size(), 2, "Path of incorrect length was created with basic algorithm"); ASSERT_EQ(path.front().getX(), 3, "Basic algorithm path content is incorrect"); ASSERT_EQ(path.front().getY(), 3, "Basic algorithm path content is incorrect"); ASSERT_EQ(path.back().getX(), 4, "Basic algorithm path content is incorrect"); ASSERT_EQ(path.back().getY(), 4, "Basic algorithm path content is incorrect"); // Trigger path = map.calculatePath(MGFASTARLIST, 3, 3, 4, 4); // Verify ASSERT_EQ(path.size(), 2, "Path of incorrect length was created with A* algorithm"); ASSERT_EQ(path.front().getX(), 3, "A* algorithm path content is incorrect"); ASSERT_EQ(path.front().getY(), 3, "A* algorithm path content is incorrect"); ASSERT_EQ(path.back().getX(), 4, "A* algorithm path content is incorrect"); ASSERT_EQ(path.back().getY(), 4, "A* algorithm path content is incorrect"); }
void Project2Test::test_MGMovingObject_setAStarPathStartMoving() { // Setup MGMovingObject m; m.enableHistory(); MGFrameworkStub mgf; IMGWindowImpl win; mgf.setWindowProperties(1024, 768, 32, false, std::string("test"), &win); mgf.init(20, 20, 16, 16); MGMap map; map.init(20, 20, 16, 16, 1024, 768); // Initialize the MO ASSERT_EQ(m.isCreated(), true, "MO was created in wrong state"); m.initialize(); m.setSpeed(0.5, 16); // Two tiles per second ASSERT_EQ(m.isIdle(), true, "MO was created in wrong state"); // Set MO location m.setTileXY(3, 3, &mgf); ASSERT_EQ(m.isIdle(), true, "MO was created in wrong state"); ASSERT_EQ(m.anyMovingMO(), false, "Some MO are moving"); ASSERT_EQ(m.getTileX(), 3, "MO created in wrong location"); ASSERT_EQ(m.getTileY(), 3, "MO created in wrong location"); ASSERT_EQ(m.getNextTileX(), 0, "MO created with wrong destination"); ASSERT_EQ(m.getNextTileY(), 0, "MO created with wrong destination"); ASSERT_EQ(m.getXOffset(), 0, "MO created in wrong location"); ASSERT_EQ(m.getYOffset(), 0, "MO created in wrong location"); ASSERT_EQ(m.getOwner(), 0, "MO created with wrong owner"); // Trigger (set an A* path from current location to one tile away) m.setPath(map.calculatePath(MGFASTARLIST, 3, 3, 4, 4)); // Verify ASSERT_EQ(m.isIdle(), true, "MO in wrong state"); ASSERT_EQ(m.anyMovingMO(), false, "Some MO are moving"); ASSERT_EQ(m.getTileX(), 3, "MO in wrong location"); ASSERT_EQ(m.getTileY(), 3, "MO in wrong location"); ASSERT_EQ(m.getNextTileX(), 0, "MO with wrong destination"); ASSERT_EQ(m.getNextTileY(), 0, "MO with wrong destination"); ASSERT_EQ(m.getXOffset(), 0, "MO in wrong location"); ASSERT_EQ(m.getYOffset(), 0, "MO in wrong location"); // Trigger m.update(&mgf); // Now the current location should have been removed from the path. MO still idle. m.update(&mgf); // New destination tile set. MO is moving. // Verify m.printHistory(); ASSERT_EQ(m.isMoving(), true, "MO in wrong state"); ASSERT_EQ(m.anyMovingMO(), true, "No MO is moving"); ASSERT_EQ(m.getTileX(), 3, "MO in wrong location"); ASSERT_EQ(m.getTileY(), 3, "MO in wrong location"); ASSERT_EQ(m.getNextTileX(), 4, "MO with wrong destination"); ASSERT_EQ(m.getNextTileY(), 4, "MO with wrong destination"); }
void Project2Test::test_MGMovingObject_setAStarPathGetStuck() { // Setup MGMovingObject m; m.enableHistory(); MGFrameworkStub mgf; IMGWindowImpl win; mgf.setWindowProperties(1024, 768, 32, false, std::string("test"), &win); mgf.init(20, 20, 16, 16); MGMap map; map.init(20, 20, 16, 16, 1024, 768); // Initialize the MO ASSERT_EQ(m.isCreated(), true, "MO was created in wrong state"); m.initialize(); m.setSpeed(0.5, 16); // Two tiles per second ASSERT_EQ(m.isIdle(), true, "MO was created in wrong state"); // Set MO location and path m.setTileXY(3, 3, &mgf); m.setPath(map.calculatePath(MGFASTARLIST, 3, 3, 4, 4)); ASSERT_EQ(m.isIdle(), true, "MO in wrong state"); m.update(&mgf); // Now the current location should have been removed from the path. MO still idle. ASSERT_EQ(m.isIdle(), true, "MO in wrong state"); // Create another MO on the destination tile to make it occupied mgf.runConsoleCommand("add mo 1 -x 4 -y 4 -owner 123", &mgf, NULL); // Trigger m.update(&mgf); // Verify - Wanted destination tile is occupied -> MO is stuck. m.printHistory(); ASSERT_EQ(m.isStuck(), true, "MO in wrong state"); ASSERT_EQ(m.anyMovingMO(), false, "Some MO are moving"); ASSERT_EQ(m.getTileX(), 3, "MO in wrong location"); ASSERT_EQ(m.getTileY(), 3, "MO in wrong location"); ASSERT_EQ(m.getNextTileX(), 3, "MO with wrong destination"); ASSERT_EQ(m.getNextTileY(), 3, "MO with wrong destination"); }