コード例 #1
0
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");
}
コード例 #2
0
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");
}
コード例 #3
0
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");
}
コード例 #4
0
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");
}
コード例 #5
0
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");
}
コード例 #6
0
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");
}
コード例 #7
0
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");
}