Open alexey-malov opened 6 years ago
> Info
Engine : Off
Gear : 0
Speed : 0
Direction : Stop
> EngineOn
> Info
Engine : On
Gear : 0
Speed : 0
Direction : Stop
> SetGear -1
> SetSpeed 10
> Info
Engine : On
Gear : -1
Speed : 10
Direction : Back <---------- Тут еще едем назад
> SetGear 0
> Info
Engine : On
Gear : 0
Speed : 10
Direction : Forward <---------- Направление резко сменилось на противоположное
>
CDriveCar::HandleCommand()
можно обойтись одним action map-ом, если функции, исполняющие команды будут принимать поток, из которого будут самостоятельно считывать нужные им аргументыbool CDriveCar::SetSpeed(int speed)
{
int gear = CCar::GetGear();
int currentSpeed = CCar::GetSpeed();
if (!IsEngineTurnedOn())
{
std::cout << " Error: Engine should be turned on" << std::endl;
} else if ((gear == 0) && (speed > currentSpeed) && (speed >= 0)) {
std::cout << " Error: Cannot set speed more than current if gear equals 0" << std::endl;
} else if (speed < 0) {
std::cout << " Error: Speed cannot be negative" << std::endl;
} else if (!IsCorrectValue(gear, speed)) {
std::cout << " Error: Speed is not correct for this gear" << std::endl;
}
CCar::SetSpeed(speed);
return true;
}
class CDriveCar : public CCar
{
void ExpectOperationSuccess(SomeObj & obj, const function<bool(SomeObj & obj)> & op, int expectedProperty1, const string & expectedProperty2, ...)
{
BOOST_REQUIRE(op(obj)); // ожидаем, что операция вернет true (успех)
// Сравниваем состояние свойства объект с ожидаемым
BOOST_CHECK_EQUAL(obj.GetProperty1(), expectedProperty1);
BOOST_CHECK_EQUAL(obj.GetProperty2(), expectedProperty2);
...
}
void ExpectOperationFailure(const SomeObj & obj, const function<bool(SomeObj & obj)> & op);
{
auto clone(obj); // сделали клон объекта
BOOST_REQUIRE(!op(clone)); // ожидаем, что операция завершится неуспешно (передаем клон)
// проверяем, что после выполнения операции состояние клона не отличается от оригинала
// (операция в случае неудачи оставляет объект в состоянии, в котором он пребывал до операции)
BOOST_CHECK_EQUAL(clone.GetProperty1(), obj.GetProperty1());
BOOST_CHECK_EQUAL(clone.GetProperty2(), obj.GetProperty2());
...
}
bool CDriveCar::SetGear(std::istream & args)
{
int gear;
string input;
args >> input;
int speed = m_car.GetSpeed();
int currentGear = m_car.GetGear();
if (IsConvertStringToInteger(input, gear))