当前位置: 首页>>代码示例>>C++>>正文


C++ House::getHealth方法代码示例

本文整理汇总了C++中House::getHealth方法的典型用法代码示例。如果您正苦于以下问题:C++ House::getHealth方法的具体用法?C++ House::getHealth怎么用?C++ House::getHealth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在House的用法示例。


在下文中一共展示了House::getHealth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: newHouse

TEST_F(SimulatorTest, fire) {
	House newHouse(Point(0, 1), 2);
	Street verticalLeft("VerticalLeft", Point(2, 2), Point(2, 1));
	Street horizontal("Horizontal", Point(2, 2), Point(4, 2));
	Street verticalRight("VerticalRight", Point(4, 3), Point(4, 2));
	ASSERT_TRUE(ptrCity->add(newHouse));
	ASSERT_TRUE(ptrCity->add(horizontal));
	ASSERT_TRUE(ptrCity->add(verticalLeft));
	ASSERT_TRUE(ptrCity->add(verticalRight));

	Simulator sim(ptrCity, ptrOutput);
	House* ptrHouse = ptrCity->getHouses()[0];
	ASSERT_TRUE(ptrHouse != NULL);

	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_EQ(2, ptrHouse->getHealth());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_EQ(1, ptrHouse->getHealth());

	EXPECT_FALSE(sim.sendFireTrucks());	// oh, there isn't even a firedepot

	// now build a firedepot
	FireDepot newDepot(Point(4, 7), Point(4, 3), "Firedepot", 1);
	ASSERT_TRUE(ptrCity->add(newDepot));
	FireDepot* ptrDepot = ptrCity->findFireDepot("Firedepot");
	ASSERT_TRUE(ptrDepot != NULL);

	EXPECT_FALSE(sim.sendFireTrucks());	// oh, there isn't even a firetruck

	// add a firetruck
	FireTruck newTruck("Truck", ptrDepot);
	ASSERT_TRUE(ptrCity->add(newTruck));
	FireTruck* ptrTruck = ptrCity->getFireTrucks()[0];
	ASSERT_TRUE(ptrTruck != NULL);

	EXPECT_TRUE(sim.sendFireTrucks());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrHouse->isFireTruckAssigned());
	EXPECT_EQ(Point(2, 1), ptrTruck->getDestination());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 1), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(ptrDepot->getEntrance(), ptrTruck->getDestination());
	EXPECT_FALSE(ptrHouse->isBurning());
	EXPECT_FALSE(ptrHouse->isFireTruckAssigned());

	EXPECT_NO_FATAL_FAILURE(sim.repairBuildings());
	EXPECT_EQ(1.5, ptrHouse->getHealth());

	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_TRUE(ptrDepot->isBurning());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 3), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_EQ(0.5, ptrHouse->getHealth());
	EXPECT_EQ(-1, ptrDepot->getHealth());
	EXPECT_TRUE(ptrDepot->isDead());
	EXPECT_FALSE(ptrDepot->isBurning());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_EQ(-0.5, ptrHouse->getHealth());
	EXPECT_EQ(-1, ptrDepot->getHealth());

	EXPECT_TRUE(sim.endSimulation());
}
开发者ID:rubenvanassche,项目名称:City-Simulator,代码行数:98,代码来源:Simulator_test.cpp


注:本文中的House::getHealth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。