/** * @throws Exception * @author Klaus Meffert */ public void testAddNaturalSelector_1() throws Exception { Configuration conf = new Configuration(); Genotype.setStaticConfiguration(conf); NaturalSelector selector = new WeightedRouletteSelector(); conf.addNaturalSelector(selector, false); assertEquals(selector, conf.getNaturalSelectors(false).get(0)); }
/** * @throws Exception * @author Klaus Meffert */ public void testGetter_0() throws Exception { Configuration conf = new Configuration(); Genotype.setStaticConfiguration(conf); assertEquals(false, conf.isLocked()); FitnessFunction fitFunc = new StaticFitnessFunction(2); conf.setFitnessFunction(fitFunc); Gene gene = new BooleanGene(conf); Chromosome sample = new Chromosome(conf, gene, 55); conf.setSampleChromosome(sample); NaturalSelector natSel = new WeightedRouletteSelector(); conf.addNaturalSelector(natSel, false); RandomGenerator randGen = new StockRandomGenerator(); conf.setRandomGenerator(randGen); IEventManager evMan = new EventManager(); conf.setEventManager(evMan); GeneticOperator mutOp = new MutationOperator(conf); conf.addGeneticOperator(mutOp); GeneticOperator croOp = new CrossoverOperator(conf); conf.addGeneticOperator(croOp); conf.setPopulationSize(7); assertEquals(fitFunc, conf.getFitnessFunction()); assertEquals(natSel, conf.getNaturalSelectors(false).get(0)); assertEquals(randGen, conf.getRandomGenerator()); assertEquals(sample, conf.getSampleChromosome()); assertEquals(evMan, conf.getEventManager()); assertEquals(7, conf.getPopulationSize()); assertEquals(2, conf.getGeneticOperators().size()); assertEquals(mutOp, conf.getGeneticOperators().get(0)); assertEquals(croOp, conf.getGeneticOperators().get(1)); }
/** * @throws Exception * @author Klaus Meffert */ public void testAddNaturalSelector_4() throws Exception { Configuration conf = new Configuration(); Genotype.setStaticConfiguration(conf); NaturalSelector selector = new WeightedRouletteSelector(); conf.addNaturalSelector(selector, true); conf.getNaturalSelectors(true).clear(); conf.addNaturalSelector(selector, true); int i = conf.getNaturalSelectors(true).size(); assertEquals(1, i); }
/** * @throws Exception * @author Klaus Meffert */ public void testAddNaturalSelector_2() throws Exception { Configuration conf = new Configuration(); Genotype.setStaticConfiguration(conf); NaturalSelector selector1 = new WeightedRouletteSelector(); NaturalSelector selector2 = new WeightedRouletteSelector(); conf.addNaturalSelector(selector1, false); assertEquals(selector1, conf.getNaturalSelectors(false).get(0)); conf.addNaturalSelector(selector2, true); assertEquals(selector2, conf.getNaturalSelectors(true).get(0)); assertEquals(selector1, conf.getNaturalSelectors(false).get(0)); try { assertEquals(null, conf.getNaturalSelectors(false).get(1)); fail(); } catch (Exception ex) {; // this is OK } }