github.com/yaricom/goNEAT@v0.0.0-20210507221059-e2110b885482/neat/trait_test.go (about) 1 package neat 2 3 import ( 4 "testing" 5 ) 6 7 func TestNewTraitAvrg(t *testing.T) { 8 t1 := &Trait{Id:1, Params:[]float64{1, 2, 3, 4, 5, 6}} 9 t2 := &Trait{Id:2, Params:[]float64{2, 3, 4, 5, 6, 7}} 10 11 tr, err := NewTraitAvrg(t1, t2) 12 if err != nil { 13 t.Error(err) 14 } 15 if tr.Id != t1.Id { 16 t.Error("tr.Id != t1.Id", tr.Id) 17 } 18 for i, p := range tr.Params { 19 if p != (t1.Params[i] + t2.Params[i]) / 2.0 { 20 t.Error("Wrong parameter at: ", i) 21 } 22 } 23 } 24 25 func TestNewTraitCopy(t *testing.T) { 26 t1 := &Trait{Id:1, Params:[]float64{1, 2, 3, 4, 5, 6}} 27 28 tr := NewTraitCopy(t1) 29 if tr.Id != t1.Id { 30 t.Error("tr.Id != t1.Id", tr.Id) 31 } 32 for i, p := range tr.Params { 33 if p != t1.Params[i] { 34 t.Error("Wrong parameter at: ", i) 35 } 36 } 37 }