LikhachevAV / OOP2016

0 stars 0 forks source link

Замечания по CCar #5

Open alexey-malov opened 7 years ago

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago

image

alexey-malov commented 7 years ago
void CCar::Info()
{
    string engineStatus = m_isEngineOn ? "on" : "off";
    string direction;
    switch (m_direction) 
    {
    case Direction::stop:
            direction = "stop";
            break;
    case Direction::forward:
            direction = "forward";
            break;
    case Direction::backward:
            direction = "backward";
            break;
    }
    cout << "Car engine is " << engineStatus << endl
        << "Current direction: " << direction << endl
        << "current gear: " << m_gear << endl
        << "current speed: " << m_speed << endl;
}
alexey-malov commented 7 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 7 years ago
Please, enter command for car: SetGear<55>
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago

image

alexey-malov commented 7 years ago
class CCar
{
private:
    bool m_isEngineOn = false;
    int m_gear = 0;
    unsigned m_speed = 0;
    Direction m_direction = Direction::stop;
    std::string m_lastErrorDescription;
    void SetDirection();

public:
    const bool IsEngineOn();
    const Direction GetDirection();
    const int GetGear();
    const unsigned GetSpeed();
    const std::string GetLastErrorDescription();
    bool EngineOn();
    bool EngineOff();
    bool SetGear(int gear);
    bool SetSpeed(unsigned speed);
};
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
Please, enter command for car: Info
Car engine is on
Current direction: backward
current gear: -1
current speed: 10
Please, enter command for car: SetGear<0>
Please, enter command for car: Info
Car engine is on
Current direction: forward
current gear: 0
current speed: 10
alexey-malov commented 7 years ago
    bool canSetGear = m_isEngineOn &&
        m_gear != gear &&
        (gear == 0 || (gear == -1) && (m_direction == Direction::stop) ||
        ((m_direction == Direction::stop || m_direction == Direction::forward) &&
            m_speed <= currentGearMaxSpeed && m_speed >= currentGearMinSpeed && gear != -1));
alexey-malov commented 7 years ago
Please, enter command for car: SetSpeed<20>
Speed at gear 0 must be between 0 and 150!