EvgeniyGlazirin / oop

0 stars 0 forks source link

Замечания по программе Car #7

Open alexey-malov opened 6 years ago

alexey-malov commented 6 years ago
1>c:\teaching\ips\2018\oop\glazyrin\oop\lab3\car\car\car.cpp(55): warning C4715: 'CCar::TurnOffEngine': not all control paths return a value
1>c:\teaching\ips\2018\oop\glazyrin\oop\lab3\car\car\car.cpp(122): warning C4715: 'CCar::SetSpeed': not all control paths return a value
alexey-malov commented 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  <---------- Направление резко сменилось на противоположное
>

image

alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
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;
}
alexey-malov commented 6 years ago
class CDriveCar : public CCar
{
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago

image

alexey-malov commented 6 years ago

image

alexey-malov commented 6 years ago

image

alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
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());
    ...
}
alexey-malov commented 6 years ago
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))
alexey-malov commented 6 years ago