void Project2Test::test_MGFramework_deleteFirstMOPerOwner() { // Setup MGFrameworkStub mgf; mgf.init(16, 16, 32, 32); mgf.runConsoleCommand("add mo 1 -owner 1", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF failed to setup MO owner"); mgf.runConsoleCommand("add mo 2 -owner 2", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 3, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 3, "MGF failed to create MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(1)->getOwner(), 2, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(2)->getOwner(), 2, "MGF failed to setup MO owner"); // Trigger mgf.runConsoleCommand("delete all mo -owner 1", &mgf, NULL); // Verify ASSERT_EQ(mgf._getNumberOfMO(), 2, "MGF failed to delete MO"); ASSERT_EQ(mgf._m_MO().size(), 2, "MGF failed to delete MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 2, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(1)->getOwner(), 2, "MGF failed to setup MO owner"); }
void Project2Test::test_MGFramework_createMO() { // Setup MGFrameworkStub mgf; ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF created with MO"); EXPECT_ERROR("MGFramework::addMO cannot create 1 MO on a 0 by 0 map"); mgf._addMO(1); ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF created MOs without initializing the map"); mgf.init(16, 16, 32, 32); // Trigger/Verify mgf._addMO(0); ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF failed to create zero MO"); mgf._addMO(1); ASSERT_EQ(mgf._getNumberOfMO(), 1, "MGF failed to create MO"); mgf._addMO(3); ASSERT_EQ(mgf._getNumberOfMO(), 4, "MGF failed to create MO"); mgf._addMO(1); ASSERT_EQ(mgf._getNumberOfMO(), 5, "MGF failed to create MO"); mgf._addMO(15); ASSERT_EQ(mgf._getNumberOfMO(), 20, "MGF failed to create MO"); mgf._addMO(0); ASSERT_EQ(mgf._getNumberOfMO(), 20, "MGF failed to create zero MO"); }
void Project2Test::test_MGFramework_resetupMO() { // Setup MGFrameworkStub mgf; mgf.init(16, 16, 32, 32); mgf._addMO(1); ASSERT_EQ(mgf._getNumberOfMO(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size() == 0, false, "MGF failed to create MO"); mgf._setupMO(mgf.nthMO(0), 4, 5, 2, 3, 0, 0, 0, 0); ASSERT_EQ(mgf.nthMO(0)->getTileX(), 4, "MGF failed to setup MO x"); ASSERT_EQ(mgf.nthMO(0)->getTileY(), 5, "MGF failed to setup MO y"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 2, "MGF failed to setup MO owner"); // Trigger mgf._setupMO(mgf.nthMO(0), 8, 9, 10, 3, 0, 0, 0, 0); ASSERT_EQ(mgf.nthMO(0)->getTileX(), 8, "MGF failed to setup MO x"); ASSERT_EQ(mgf.nthMO(0)->getTileY(), 9, "MGF failed to setup MO y"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 10, "MGF failed to setup MO owner"); mgf._deleteMO(mgf.nthMO(0)); mgf._addMO(1); mgf._setupMO(mgf.nthMO(0), 4, 5, 2, 3, 0, 0, 0, 0); // Verify ASSERT_EQ(mgf.nthMO(0)->getTileX(), 4, "MGF failed to setup MO x"); ASSERT_EQ(mgf.nthMO(0)->getTileY(), 5, "MGF failed to setup MO y"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 2, "MGF failed to setup MO owner"); }
void Project2Test::test_MGStationaryObject_setTileXY() { // Setup MGStationaryObject a; // Dummy MGStationaryObject b; // Dummy MGStationaryObject c; // Dummy MGStationaryObject s; MGFrameworkStub mgf; IMGWindowImpl win; mgf.setWindowProperties(1024, 768, 32, false, std::string("test"), &win); mgf.init(20, 20, 16, 16); ASSERT_EQ(s.getTileX(), 0, "SO created in wrong location"); ASSERT_EQ(s.getTileY(), 0, "SO created in wrong location"); ASSERT_EQ(s.getID() != 0, true, "SO ID not generated correctly"); ASSERT_EQ(mgf.m_Map.occupant(0, 0), 0, "Map tile is already occupied"); // Trigger s.setTileXY(0, 0, &mgf); // Verify ASSERT_EQ(mgf.m_Map.occupant(0, 0), s.getID(), "SO was not able to occupy a map tile"); // Trigger s.setTileXY(9, 8, &mgf); // Verify ASSERT_EQ(mgf.m_Map.occupant(9, 8), s.getID(), "SO was not able to occupy a map tile"); ASSERT_EQ(mgf.m_Map.occupant(0, 0), 0, "Map tile is still occupied"); ASSERT_EQ(s.getTileX(), 9, "SO location not updated correctly"); ASSERT_EQ(s.getTileY(), 8, "SO location not updated correctly"); }
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_MGFramework_markMO() { // Setup MGFrameworkStub mgf; mgf.init(16, 16, 32, 32); mgf.runConsoleCommand("add mo 1", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf._getNumberOfMarkedMO(), 0, "MGF created marked MO"); // Trigger mgf.runConsoleCommand("mo 0 mark", &mgf, NULL); // Verify ASSERT_EQ(mgf._getNumberOfMarkedMO(), 1, "MGF failed to mark MO"); }
void Project2Test::test_MGFramework_createMOAtLocation() { // Setup MGFrameworkStub mgf; mgf.init(16, 16, 32, 32); ASSERT_EQ(mgf.m_Map.occupant(10, 11), 0, "Target tile already occupied"); // Trigger mgf.runConsoleCommand("add mo 1 -x 10 -y 11", &mgf, NULL); // Verify ASSERT_EQ(mgf._getNumberOfMO(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf.nthMO(0)->getTileX(), 10, "MGF failed to create MO at location"); ASSERT_EQ(mgf.nthMO(0)->getTileY(), 11, "MGF failed to create MO at location"); ASSERT_EQ(mgf.m_Map.occupant(10, 11), mgf.nthMO(0)->getID(), "MGF failed to occupy tile"); }
void Project2Test::test_MGFramework_deleteAllMO() { // Setup MGFrameworkStub mgf; ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF created with MO"); mgf.init(16, 16, 32, 32); mgf._addMO(15); ASSERT_EQ(mgf._getNumberOfMO(), 15, "MGF failed to create MO"); // Trigger mgf.runConsoleCommand("delete all mo", &mgf, NULL); // Verify ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF failed to delete all MO"); // Delete all MO when no MO exist mgf.runConsoleCommand("delete all mo", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF failed to delete all MO on empty MO list"); }
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"); }
void Project2Test::test_MGFramework_markMOIndexInSymbolTable() { // Setup MGFrameworkStub mgf; mgf.init(16, 16, 32, 32); mgf.runConsoleCommand("add mo 2", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 2, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 2, "MGF failed to create MO"); ASSERT_EQ(mgf._getNumberOfMarkedMO(), 0, "MGF created marked MO"); MGSymbolTable s; s.addSymbol("moIndex", 1); ASSERT_EQ(s.hasValue("moIndex"), true, "MGF failed to create symbol"); ASSERT_EQ(s.getValue("moIndex"), 1, "MGF failed to create symbol"); // Trigger mgf.runConsoleCommand("mo moIndex mark", &mgf, &s); // Verify ASSERT_EQ(mgf._getNumberOfMarkedMO(), 1, "MGF failed to mark MO"); }
void Project2Test::test_MGFramework_deleteMO() { // Setup MGFrameworkStub mgf; ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF created with MO"); mgf.init(16, 16, 32, 32); mgf._addMO(15); ASSERT_EQ(mgf._getNumberOfMO(), 15, "MGF failed to create MO"); // Trigger/Verify // Delete first MO mgf._deleteMO(mgf.nthMO(0)); ASSERT_EQ(mgf._getNumberOfMO(), 14, "MGF failed to delete MO"); mgf._deleteMO(mgf.nthMO(0)); ASSERT_EQ(mgf._getNumberOfMO(), 13, "MGF failed to delete MO"); mgf._deleteMO(mgf.nthMO(0)); ASSERT_EQ(mgf._getNumberOfMO(), 12, "MGF failed to delete MO"); // Delete last MO mgf._deleteMO(mgf.nthMO(11)); ASSERT_EQ(mgf._getNumberOfMO(), 11, "MGF failed to delete MO"); // Delete arbitrary MO mgf._deleteMO(mgf.nthMO(7)); ASSERT_EQ(mgf._getNumberOfMO(), 10, "MGF failed to delete MO"); // Delete MO outside container mgf._deleteMO(mgf.nthMO(17)); ASSERT_EQ(mgf._getNumberOfMO(), 10, "MGF failed to delete zero MO"); // Delete all MO mgf._deleteAllMO(); ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF failed to delete MO"); // Delete all MO when no MO exist mgf._deleteAllMO(); ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF failed to run deleteAllMO"); }
void Project2Test::test_MGFramework_oneMOStartsToTakeAStepLeft() { // Setup MGFrameworkStub mgf; IMGWindowImpl win; mgf.setWindowProperties(1024, 768, 32, false, std::string("test"), &win); mgf.init(16, 16, 32, 32); mgf.runConsoleCommand("add mo 1 -x 10 -y 10", &mgf, NULL); ASSERT_EQ(mgf._m_MO().size(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf.nthMO(0)->getTileX(), 10, "MGF failed to create MO at location"); ASSERT_EQ(mgf.nthMO(0)->getTileY(), 10, "MGF failed to create MO at location"); ASSERT_EQ(mgf.nthMO(0)->getNextTileX(), 10, "MO already had a destination"); ASSERT_EQ(mgf.nthMO(0)->getNextTileY(), 10, "MO already had a destination"); // ASSERT_EQ(mgf.nthMO(0)->getNextTileX(), 10, "MGF failed to initialize MO next tile"); // ASSERT_EQ(mgf.nthMO(0)->getNextTileY(), 10, "MGF failed to initialize MO next tile"); ASSERT_EQ(mgf.m_Map.occupant(10, 10), mgf.nthMO(0)->getID(), "MGF failed to occupy tile"); ASSERT_EQ(mgf.m_Map.occupant(9, 10), 0, "Target tile already occupied"); // Trigger mgf.runConsoleCommand("mo 0 setdestination 9 10", &mgf, NULL); mgf.nthMO(0)->update(&mgf); // Current location removed from path win.elapseTime(16); mgf.nthMO(0)->update(&mgf); // Destination set and MO moving win.elapseTime(16); mgf.nthMO(0)->update(&mgf); // Moving win.elapseTime(16); mgf.nthMO(0)->update(&mgf); // Moving // Verify ASSERT_EQ(mgf.m_Map.occupant(10, 10), 0, "MGF failed to unoccupy tile"); ASSERT_EQ(mgf.m_Map.occupant(9, 10), mgf.nthMO(0)->getID(), "MGF failed to occupy tile"); ASSERT_EQ(mgf.nthMO(0)->getTileX(), 10, "MO left location of creation too early"); ASSERT_EQ(mgf.nthMO(0)->getTileY(), 10, "MO left location of creation too early"); ASSERT_EQ(mgf.nthMO(0)->getNextTileX(), 9, "MO did not get a destination"); ASSERT_EQ(mgf.nthMO(0)->getNextTileY(), 10, "MO did not get a destination"); ASSERT_EQ(mgf.nthMO(0)->getXOffset() < 0, true, "MO did not start moving"); ASSERT_EQ(mgf.nthMO(0)->getYOffset(), 0, "MO moved in the wrong direction"); }
void Project2Test::test_MGFramework_deleteFirstMO() { // Setup MGFrameworkStub mgf; ASSERT_EQ(mgf._getNumberOfMO(), 0, "MGF created with MO"); mgf.init(16, 16, 32, 32); mgf._addMO(2); ASSERT_EQ(mgf._getNumberOfMO(), 2, "MGF failed to create MO"); std::list<MGMovingObject>::iterator it = mgf.nthMO(0); mgf.nthMO(0)->setOwner(0); mgf.nthMO(1)->setOwner(1); // Trigger - delete first MO mgf._deleteMO(it); // Verify ASSERT_EQ(mgf._getNumberOfMO(), 1, "MGF failed to delete MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF did not delete the right MO"); // Setup - create another 3 MO it = mgf.nthMO(0); mgf._addMO(3); mgf.nthMO(0)->setOwner(0); mgf.nthMO(1)->setOwner(1); mgf.nthMO(2)->setOwner(2); mgf.nthMO(3)->setOwner(3); // Trigger - delete first MO again mgf._deleteMO(it); // Verify ASSERT_EQ(mgf._getNumberOfMO(), 3, "MGF failed to delete MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF did not delete the right MO"); ASSERT_EQ(mgf.nthMO(1)->getOwner(), 2, "MGF did not delete the right MO"); ASSERT_EQ(mgf.nthMO(2)->getOwner(), 3, "MGF did not delete the right MO"); }
void Project2Test::test_MGFramework_deleteFewMO() { // Setup MGFrameworkStub mgf; mgf.init(16, 16, 32, 32); mgf.runConsoleCommand("add mo 1 -owner 1", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 1, "MGF failed to create MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF failed to setup MO owner"); mgf.runConsoleCommand("add mo 2 -owner 2", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 3, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 3, "MGF failed to create MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(1)->getOwner(), 2, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(2)->getOwner(), 2, "MGF failed to setup MO owner"); mgf.runConsoleCommand("add mo 1 -owner 3", &mgf, NULL); ASSERT_EQ(mgf._getNumberOfMO(), 4, "MGF failed to create MO"); ASSERT_EQ(mgf._m_MO().size(), 4, "MGF failed to create MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(1)->getOwner(), 2, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(2)->getOwner(), 2, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(3)->getOwner(), 3, "MGF failed to setup MO owner"); // Trigger - delete the two middle MO out of the four mgf._deleteMO(mgf.nthMO(1)); mgf._deleteMO(mgf.nthMO(1)); // Verify ASSERT_EQ(mgf._getNumberOfMO(), 2, "MGF failed to delete MO"); ASSERT_EQ(mgf._m_MO().size(), 2, "MGF failed to delete MO"); ASSERT_EQ(mgf.nthMO(0)->getOwner(), 1, "MGF failed to setup MO owner"); ASSERT_EQ(mgf.nthMO(1)->getOwner(), 3, "MGF failed to setup MO owner"); }