Провести ревью кода.
Условие
Заголовок раздела «Условие»Провести ревью кода.
type parrotType int
const ( TypeEuropean parrotType = 1 TypeAfrican parrotType = 2 TypeNorwegianBlue parrotType = 3)
// Parrot has a Speed.type Parrot interface { Speed() (float64, error)}
type mixedParrot struct { _type parrotType numberOfCoconuts int voltage float64 nailed bool}
func CreateParrot(pt parrotType, numberOfCoconuts int, voltage float64, nailed bool) Parrot { return mixedParrot{ _type: pt, numberOfCoconuts: numberOfCoconuts, voltage: voltage, nailed: nailed, }}
func (parrot mixedParrot) Speed() (float64, error) { switch parrot._type { case TypeEuropean: return parrot.baseSpeed(), nil case TypeAfrican: return math.Max(0, parrot.baseSpeed()-parrot.loadFactor()*float64(parrot.numberOfCoconuts)), nil case TypeNorwegianBlue: if parrot.nailed { return 0, nil } return parrot.computeBaseSpeedForVoltage(parrot.voltage), nil default: return 0, errors.New("should be unreachable ") }}
func (parrot mixedParrot) computeBaseSpeedForVoltage(voltage float64) float64 { return math.Min(24.0, voltage*parrot.baseSpeed())}
func (parrot mixedParrot) loadFactor() float64 { return 9.0}
func (parrot mixedParrot) baseSpeed() float64 { return 12.0}Решение
Заголовок раздела «Решение»Источник: Wildberries / WB - 12
← (код без описания) · Все задачи · Go · Что выведет и почему? →