<commit_before>package genetics

import (
	"github.com/yaricom/goNEAT/v2/neat"
	"math/rand"
	"testing"
)

func runSequentialPopulationEpochExecutor_NextEpoch(pop *Population, conf *neat.NeatContext) error {
	ex := SequentialPopulationEpochExecutor{}

	for i := 0; i < 100; i++ {
		err := ex.NextEpoch(i+1, pop, conf)
		if err != nil {
			return err
		}
	}
	return nil

}

func runParallelPopulationEpochExecutor_NextEpoch(pop *Population, conf *neat.NeatContext) error {
	ex := ParallelPopulationEpochExecutor{}

	for i := 0; i < 100; i++ {
		err := ex.NextEpoch(i+1, pop, conf)
		if err != nil {
			return err
		}
	}
	return nil
}

func TestPopulationEpochExecutor_NextEpoch(t *testing.T) {
	rand.Seed(42)
	in, out, nmax, n := 3, 2, 15, 3
	recurrent := false
	linkProb := 0.8
	conf := neat.NeatContext{
		CompatThreshold: 0.5,
		DropOffAge:      1,
		PopSize:         30,
		BabiesStolen:    10,
		RecurOnlyProb:   0.2,
	}
	neat.LogLevel = neat.LogLevelInfo
	gen := newGenomeRand(1, in, out, n, nmax, recurrent, linkProb)
	pop, err := NewPopulation(gen, &conf)
	if err != nil {
		t.Error(err)
	}
	if pop == nil {
		t.Error("pop == nil")
	}

	// test sequential executor
	err = runSequentialPopulationEpochExecutor_NextEpoch(pop, &conf)
	if err != nil {
		t.Error(err)
	}

	// test parallel executor
	err = runParallelPopulationEpochExecutor_NextEpoch(pop, &conf)
	if err != nil {
		t.Error(err)
	}
}<commit_msg>Fixed population's epoch executors tests<commit_after>package genetics

import (
	"github.com/pkg/errors"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"github.com/yaricom/goNEAT/v2/neat"
	"math/rand"
	"testing"
)

func sequentialExecutorNextEpoch(pop *Population, conf *neat.NeatContext) error {
	ex := SequentialPopulationEpochExecutor{}

	for i := 0; i < 100; i++ {
		err := ex.NextEpoch(i+1, pop, conf)
		if err != nil {
			return errors.Wrapf(err, "failed at: %d epoch", i)
		}
	}
	return nil

}

func parallelExecutorNextEpoch(pop *Population, conf *neat.NeatContext) error {
	ex := ParallelPopulationEpochExecutor{}

	for i := 0; i < 100; i++ {
		err := ex.NextEpoch(i+1, pop, conf)
		if err != nil {
			return errors.Wrapf(err, "failed at: %d epoch", i)
		}
	}
	return nil
}

func TestPopulationEpochExecutor_NextEpoch(t *testing.T) {
	rand.Seed(42)
	in, out, nmax, n := 3, 2, 15, 3
	linkProb := 0.8
	conf := neat.NeatContext{
		CompatThreshold: 0.5,
		DropOffAge:      1,
		PopSize:         30,
		BabiesStolen:    10,
		RecurOnlyProb:   0.2,
	}
	neat.LogLevel = neat.LogLevelInfo
	gen := newGenomeRand(1, in, out, n, nmax, false, linkProb)
	pop, err := NewPopulation(gen, &conf)
	require.NoError(t, err, "failed to create population")
	require.NotNil(t, pop, "population expected")

	// test sequential executor
	err = sequentialExecutorNextEpoch(pop, &conf)
	assert.NoError(t, err, "failed to run sequential epoch executor")

	// test parallel executor
	err = parallelExecutorNextEpoch(pop, &conf)
	assert.NoError(t, err, "failed to run parallel epoch executor")
}
{'fraction_non_alphanumeric': 0.1345707656612529, 'fraction_numerical': 0.019887305270135897, 'mean_word_length': 3.9475409836065576, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6330030', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1146, 'n_words': 278}