Skip to content

Commit 307b33c

Browse files
committed
Add Speciator runtime error in GA.Enhance
1 parent bbf66f7 commit 307b33c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ga_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,18 @@ func TestGAEnhanceModelRuntimeError(t *testing.T) {
271271
}
272272
ga.Model = model
273273
}
274+
275+
func TestGAEnhanceSpeciatorRuntimeError(t *testing.T) {
276+
var speciator = ga.Speciator
277+
ga.Speciator = SpecRuntimeError{}
278+
// Check invalid speciator doesn't raise error
279+
if ga.Validate() != nil {
280+
t.Errorf("Expected %s, got %s", nil, ga.Validate())
281+
}
282+
// Enhance
283+
var err = ga.Enhance()
284+
if err == nil {
285+
t.Error("An error should have been raised")
286+
}
287+
ga.Speciator = speciator
288+
}

setup_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ type ModRuntimeError struct{}
8787

8888
func (mod ModRuntimeError) Apply(pop *Population) error { return errors.New("") }
8989
func (mod ModRuntimeError) Validate() error { return nil }
90+
91+
// Runtime error speciator
92+
93+
type SpecRuntimeError struct{}
94+
95+
func (spec SpecRuntimeError) Apply(indis Individuals, rng *rand.Rand) ([]Individuals, error) {
96+
return []Individuals{indis, indis}, errors.New("")
97+
}
98+
func (spec SpecRuntimeError) Validate() error { return nil }

0 commit comments

Comments
 (0)