Перейти к содержимому

Провести ревью кода.

go · basicsWildberries / WB - 3 (Команда отзывов)3 кв 2025не решено

Провести ревью кода.

type parrotType int
const (
TypeEuropean parrotType = iota
TypeAfrican
TypeNorwegianBlue parrotType = 3
)
type Parrot interface {
Speed() (float64, error)
}
type mixedParrot struct {
_type parrotType
numberOfCoconuts int
voltage float64
nailed bool
}
func CreateParrot(t parrotType, numberOfCoconuts int, voltage float64, nailed bool) Parrot {
return &mixedParrot{t, numberOfCoconuts, voltage, 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 - 3 (Команда отзывов) · 3 кв 2025

← GetData возвращает данные из getter, ст… · Все задачи · Go · Что выведет? →