Пример #1
0
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");
}
Пример #2
0
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");
}
Пример #3
0
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");
}
Пример #4
0
void Project2Test::test_MGMap_initialize()
{
	MGMap map;
	MGFrameworkStub mgf;

	map.init(10, 10, 16, 16, 640, 480);
	ASSERT_EQ(map.getWidth(), 10, "Map was created with wrong width");
	ASSERT_EQ(map.getHeight(), 10, "Map was created with wrong height");
	ASSERT_EQ(map.getTileWidth(), 16, "Map was created with wrong tile width");
	ASSERT_EQ(map.getTileHeight(), 16, "Map was created with wrong tile height");
	ASSERT_EQ(map.getWindowWidth(), 640, "Map was created with wrong window width");
	ASSERT_EQ(map.getWindowHeight(), 480, "Map was created with wrong window height");

	map.reInit(12, 16, 32, 32);
	ASSERT_EQ(map.getWidth(), 12, "Map was created with wrong width");
	ASSERT_EQ(map.getHeight(), 16, "Map was created with wrong height");
	ASSERT_EQ(map.getTileWidth(), 32, "Map was created with wrong tile width");
	ASSERT_EQ(map.getTileHeight(), 32, "Map was created with wrong tile height");
	ASSERT_EQ(map.getWindowWidth(), 640, "Map was created with wrong window width");
	ASSERT_EQ(map.getWindowHeight(), 480, "Map was created with wrong window height");

	map.runConsoleCommand("map setsize 23 25 16 16", &mgf, NULL);
	ASSERT_EQ(map.getWidth(), 23, "Map was created with wrong width");
	ASSERT_EQ(map.getHeight(), 25, "Map was created with wrong height");
	ASSERT_EQ(map.getTileWidth(), 16, "Map was created with wrong tile width");
	ASSERT_EQ(map.getTileHeight(), 16, "Map was created with wrong tile height");
	ASSERT_EQ(map.getWindowWidth(), 640, "Map was created with wrong window width");
	ASSERT_EQ(map.getWindowHeight(), 480, "Map was created with wrong window height");
}