Exemplo n.º 1
0
	void CheckTransmissionSpeedRange(int gear, int minSpeed, int maxSpeed, int currentSpeed)
	{
		ExpectOperationSucceeds([=] { return car.SetGear(gear);}, gear, currentSpeed);
		ExpectOperationFails([=] { return car.SetSpeed(minSpeed - 1);});
		ExpectOperationFails([=] { return car.SetSpeed(maxSpeed + 1);});
		ExpectOperationSucceeds([=] { return car.SetSpeed(minSpeed);}, gear, minSpeed);
		ExpectOperationSucceeds([=] { return car.SetSpeed((minSpeed + maxSpeed) / 2);}, gear, (minSpeed + maxSpeed)/ 2);
		ExpectOperationSucceeds([=] { return car.SetSpeed(maxSpeed);}, gear, maxSpeed);
	}
Exemplo n.º 2
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;
}