forked from MaxHalford/eaopt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
individual_test.go
60 lines (55 loc) · 1.48 KB
/
individual_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gago
import (
"testing"
)
func TestCloneIndividual(t *testing.T) {
var (
rng = newRandomNumberGenerator()
genome = NewVector(rng)
indi1 = NewIndividual(genome, rng)
indi2 = indi1.Clone(rng)
)
if &indi1 == &indi2 || &indi1.Genome == &indi2.Genome {
t.Error("Individual was not deep copied")
}
}
func TestEvaluateIndividual(t *testing.T) {
var (
rng = newRandomNumberGenerator()
genome = NewVector(rng)
indi = NewIndividual(genome, rng)
)
if indi.Evaluated {
t.Error("Individual shouldn't have Evaluated set to True")
}
indi.Evaluate()
if !indi.Evaluated {
t.Error("Individual should have Evaluated set to True")
}
}
func TestMutateIndividual(t *testing.T) {
var (
rng = newRandomNumberGenerator()
genome = NewVector(rng)
indi = NewIndividual(genome, rng)
)
indi.Evaluate()
indi.Mutate(rng)
if indi.Evaluated {
t.Error("Individual shouldn't have Evaluated set to True")
}
}
func TestCrossoverIndividual(t *testing.T) {
var (
rng = newRandomNumberGenerator()
indi1 = NewIndividual(NewVector(rng), rng)
indi2 = NewIndividual(NewVector(rng), rng)
offspring1, offspring2 = indi1.Crossover(indi2, rng)
)
if offspring1.Evaluated || offspring2.Evaluated {
t.Error("Offsprings shouldn't have Evaluated set to True")
}
if &offspring1 == &indi1 || &offspring1 == &indi2 || &offspring2 == &indi1 || &offspring2 == &indi2 {
t.Error("Offsprings shouldn't share pointers with parents")
}
}