The unsigned int mod.NOffsprings can be never negative hence here is a logic bug.
if mod.NOffsprings <= 0 {
return errors.New("NOffsprings has to higher than 0")
}
Could this not just be a int as uint normally used in Go just for binary operations?
models.go:217
// Validate ModDownToSize fields.
func (mod ModDownToSize) Validate() error {
// Check the number of offsprings value
if mod.NOffsprings <= 0 {
return errors.New("NOffsprings has to higher than 0")
}
// Check the first selection method presence
if mod.SelectorA == nil {
return errNilSelector
}
// Check the first selection method parameters
var errSelectorA = mod.SelectorA.Validate()
if errSelectorA != nil {
return errSelectorA
}
// Check the second selection method presence
if mod.SelectorB == nil {
return errNilSelector
}
// Check the second selection method parameters
var errSelectorB = mod.SelectorB.Validate()
if errSelectorB != nil {
return errSelectorB
}
// Check the mutation rate in the presence of a mutator
if mod.MutRate < 0 || mod.MutRate > 1 {
return errInvalidMutRate
}
return nil
}
The unsigned int mod.NOffsprings can be never negative hence here is a logic bug.
Could this not just be a int as uint normally used in Go just for binary operations?
models.go:217