Open alexey-malov opened 5 years ago
[x] Если вы ввели структуру ChannelInfo, то пусть метод CTvSet::GetChannelList возвращает ее а не pair.
[x] Тип pair плохо подходит для интерфейсных вещей. Лучше сделать структуру с полями number и name, чем first и second
bool CTVSet::SetChannelName(int channel, string const& name)
{
bool isAvailableChannel = (channel >= 1) && (channel <= 99);
if (!isAvailableChannel || !m_isOn)
{
return false;
}
if (CTVSet::GetChannelByName(name) != 0)
CTVSet::
писать в данном случае for (auto currChannel= m_channelInfo.begin(); currChannel != m_channelInfo.end(); currChannel++)
{
if (currChannel->first == channel)
{
currChannel->second = name;
return true;
}
}
> Info
TV is turned on
Channel is: 1
4 - TV 3
9 - 1st
> SelectChannel 1st
TV switched on 1 channel.
[ ] Если номер канала начинается с цифры, то RemoteControl ошибочно воспринимает его в виде числа.
[ ] В тестах RemoteControl надо проверить эту ситуацию
function<bool(CTVSet& tv)> SelectChannel(int channel)
{
return [channel](CTVSet& tv) {
return tv.SelectChannel(channel);
};
}
function<bool(CTVSet& tv)> SetChannelName(int channel, const string& name)
{
return [channel, name](CTVSet& tv) {
return tv.SetChannelName(channel, name);
};
}
...
ExpectOperationSuccess(tv, SelectChannel(99), 99);
SCENARIO("deleting channel")
{
GIVEN("A turned of TV")
{
CTVSet tv;
WHEN("TV is turned on")
{
tv.TurnOn();
THEN("if the channel is named, you can delete the name")
{
tv.SetChannelName(1, "ORT");
CHECK(tv.GetChannel() == 1);
tv.DeleteChannelName("ORT");
CHECK(tv.GetChannelName(1) == "");
}
AND_THEN("if the channel name is not assigned the status will not change")
{
ExpectOperationFailure(tv, [](CTVSet& tv) {return tv.DeleteChannelName("TNT"); });
SCENARIO("Channel deletion")
{
GIVEN("A turned on TV with associated channel name")
{
CTVSet tv;
tv.TurnOn();
tv.SetChannelName(3, "TV 3");
WHEN("deleting the associated channel")
{
CHECK(tv.DeleteChannelName("TV 3"));
THEN("the deleted channel can not be selected")
{
ExpectOperationFailure(tv, SelectChannel("TV 3"));
}
}
}
}
int CTVSet::ChannelNumberByName(string const& name, vector<channelInfo> const& channelInfo)
{
for (auto currChannel = channelInfo.begin(); currChannel != channelInfo.end(); currChannel++)
{
if (currChannel->channelName == name)
{
return currChannel->channel;
}
}
return 0;
}
CRemoteControl::isValidChannel
должен начинаться с заглавной буквы
void ExpectOperationFailure(const CTVSet& tv, const function<bool(CTVSet&tv)>& op) { CTVSet tvCopy(tv); // копия телевизора, над которой будет выполняться операция CHECK(!op(tvCopy)); // убедились, что операция (над копией) завершится неуспешно // сравниваем включенность и канал с прежними значениями CHECK(tvCopy.IsTurnedOn() == tv.IsTurnedOn()); CHECK(tvCopy.GetChannel() == tv.GetChannel()); }
TEST_CASE("TV can select channels from 1 to 99 only when it is on") { CTVSet tv; tv.TurnOn();
}