Exemplo n.º 1
0
	void ExpectOperationSucceeds(Op && op, int expectedGear, int expectedSpeed, bool engineIsOn = true)
	{
		BOOST_CHECK(op());

		BOOST_CHECK_EQUAL(car.IsEngineOn(), engineIsOn);
		BOOST_CHECK_EQUAL(car.GetGear(), expectedGear);
		BOOST_CHECK_EQUAL(car.GetSpeed(), abs(expectedSpeed));
		BOOST_CHECK(car.GetMovementType() == (expectedSpeed > 0 ? (expectedGear > 0 ? CCar::MovementType::FORWARD : expectedGear == 0 ? CCar::MovementType::NONE : CCar::MovementType::BACK) : CCar::MovementType::STAY));
	}
Exemplo n.º 2
0
	void ExpectOperationFails(Op && op)
	{
		const CCar clone(car);

		BOOST_CHECK(!op());

		BOOST_CHECK_EQUAL(car.IsEngineOn(), clone.IsEngineOn());
		BOOST_CHECK_EQUAL(car.GetGear(), clone.GetGear());
		BOOST_CHECK_EQUAL(car.GetSpeed(), clone.GetSpeed());
		BOOST_CHECK_EQUAL(car.GetMovementType(), clone.GetMovementType());
	}
Exemplo n.º 3
0
int _tmain(int argc, _TCHAR* argv[])
{
	CCar car;
	map<CCar::Direction, string> directionToString =
	{
		{ CCar::Direction::FORWARD, "forward" },
		{ CCar::Direction::BACKWARD, "backward" },
		{ CCar::Direction::STILL, "still" }
	};

	map<CCar::Err, string> errToStr =
	{
		{ CCar::Err::EngineTurnedOffSpeed, "Engine turned off, impossible to set given speed." },
		{ CCar::Err::EngineTurnedOffGear, "Engine turned off, impossible to set given gear." },
		{ CCar::Err::AlreadyTurnedOff, "Engine is already turned off." },
		{ CCar::Err::CanNotTurnOff, "Engine can not be turned off at current speed and gear." },
		{ CCar::Err::InvalidGear, "No such gear." },
		{ CCar::Err::InvalidSpeed, "Impossible to set given speed." },
		{ CCar::Err::InvalidSpeedForGivenGear, "Impossible to set given speed at current gear." },
		{ CCar::Err::InvalidGearForGivenSpeed, "Impossible to set given gear at current speed." }
	};

	map<bool, string> isEngineTurnedOnToStr =
	{
		{ true, " is turned on" },
		{ false, " is turned off" },
	};
	
	string curQuery;
	Commands command;
	int value;
	while (getline(cin, curQuery))
	{
		curQuery.push_back('\n');
		if (AssignCommand(curQuery, command, value))
		{
			switch (command)
			{
			case Info:
				if (car.IsEngineTurnedOn())
				{
					cout << "Engine turned on.\n";
				}
				else
				{
					cout << "Engine turned off.\n";
				}
				cout << "Direction - " << directionToString[car.GetDirection()] << ".\n";
				cout << "Speed - " << car.GetSpeed() << ".\n";
				cout << "Gear - " << car.GetGear() << ".\n";
				break;
			case EngineOn:
				if (!car.TurnOnEngine())
				{
					cout << "Engine is already turned on.\n";
				}
				break;
			case EngineOff:
				if (!car.TurnOffEngine())
				{
					cout << errToStr[car.GetLastErr()] << '\n';
				}
				break;
			case SetGear:
				if (!car.SetGear(value))
				{
					cout << errToStr[car.GetLastErr()] << '\n';
				}
				break;
			case SetSpeed:
				if (!car.SetSpeed(value))
				{
					cout << errToStr[car.GetLastErr()] << '\n';
				}
				break;
			}
		}
		else
		{
			cout << "Available commands:Info, EngineOn, EngineOff, SetSpeed <speed>, SetGear <gear>.\n";
		}		
	}
	return 0;
}
Exemplo n.º 4
0
void CheckGear(CCar & car, CCar::Gear gear)
{
	BOOST_CHECK(car.GetGear() == gear);
}