Example #1
0
// test crossover between two trees
func TestCrossover(t *testing.T) {
	pset := initPset(true)
	exprs := testExprs(pset)
	breed := gp.CxOnePoint()
	parent := gp.Population{gp.Create(exprs[1]), gp.Create(exprs[2])}
	t.Log("Before:\n", parent[0], "\n", parent[1])
	for i := 0; i < 5; i++ {
		child := breed.Variate(parent)
		t.Log("After:", i, "\n", child[0], "\n", child[1])
	}
}
Example #2
0
// test depth and size attributes
func TestDepth(t *testing.T) {
	pset := initPset(true)
	exprs := testExprs(pset)
	ind := gp.Create(exprs[2])
	depth, size := ind.Depth(), ind.Size()
	t.Logf("%s depth=%d size=%d\n", ind, depth, size)
	if depth != 3 || size != 9 {
		t.Errorf("got depth=%d size=%d - expected 3 9", depth, size)
	}
}