001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.math.genetics;
018
019 import static org.junit.Assert.*;
020
021 import java.util.Iterator;
022
023 import org.junit.Test;
024
025 public class FixedGenerationCountTest {
026
027 @Test
028 public void testIsSatisfied() {
029 FixedGenerationCount fgc = new FixedGenerationCount(20);
030
031 int cnt = 0;
032 Population pop = new Population() {
033 public void addChromosome(Chromosome chromosome) {
034 // unimportant
035 }
036 public Chromosome getFittestChromosome() {
037 // unimportant
038 return null;
039 }
040 public int getPopulationLimit() {
041 // unimportant
042 return 0;
043 }
044 public int getPopulationSize() {
045 // unimportant
046 return 0;
047 }
048 public Population nextGeneration() {
049 // unimportant
050 return null;
051 }
052 public Iterator<Chromosome> iterator() {
053 // unimportant
054 return null;
055 }
056 };
057
058 while (!fgc.isSatisfied(pop))
059 cnt++;
060 assertEquals(20, cnt);
061 }
062
063 }