-
Notifications
You must be signed in to change notification settings - Fork 10
/
individual_test.go
44 lines (41 loc) · 985 Bytes
/
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
package evoli
import "testing"
func TestNewIndividual(t *testing.T) {
cases := []struct {
indiv Individual
expected float64
}{
{NewIndividual(0.7), 0.7},
{NewIndividual(54.0), 54.0},
{NewIndividual(0), 0},
{NewIndividualSync(0.7), 0.7},
{NewIndividualSync(54.0), 54.0},
{NewIndividualSync(0), 0},
}
for _, c := range cases {
got := c.indiv.Fitness()
if got != c.expected {
t.Errorf("expected %f got %f", c.expected, got)
}
}
}
func TestFitness(t *testing.T) {
cases := []struct {
indiv Individual
in, expected float64
}{
{NewIndividual(0), 0.7, 0.7},
{NewIndividual(0), 54.0, 54.0},
{NewIndividual(10), 0, 0},
{NewIndividualSync(0), 0.7, 0.7},
{NewIndividualSync(0), 54.0, 54.0},
{NewIndividualSync(10), 0, 0},
}
for _, c := range cases {
c.indiv.SetFitness(c.in)
got := c.indiv.Fitness()
if got != c.expected {
t.Errorf("indiv.SetFitness(%f); indiv.Fitness() == %f, expected %f", c.in, got, c.expected)
}
}
}