Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOffsprings has to higher than 0 #41

Open
tegk opened this issue Oct 17, 2019 · 3 comments
Open

NOffsprings has to higher than 0 #41

tegk opened this issue Oct 17, 2019 · 3 comments

Comments

@tegk
Copy link

tegk commented Oct 17, 2019

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
}
@MaxHalford
Copy link
Owner

Good catch! The check has to be removed.

@tegk
Copy link
Author

tegk commented Oct 18, 2019

so simply removing

// Check the number of offsprings value
	if mod.NOffsprings <= 0 {
		return errors.New("NOffsprings has to higher than 0")
	}

is fine?

@MaxHalford
Copy link
Owner

Yes indeed! There might also be one or two unit test cases that will break, but I'm not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants