1 10 package org.jgap.impl; 11 12 import java.util.*; 13 import org.jgap.*; 14 import junit.framework.*; 15 16 22 public class ChainOfSelectorsTest 23 extends JGAPTestCase { 24 25 private final static String CVS_REVISION = "$Revision: 1.10 $"; 26 27 public static Test suite() { 28 TestSuite suite = new TestSuite(ChainOfSelectorsTest.class); 29 return suite; 30 } 31 32 36 public void testConstruct_0() { 37 new ChainOfSelectors(); 38 } 39 40 44 public void testClear_0() { 45 ChainOfSelectors c = new ChainOfSelectors(); 46 assertTrue(c.isEmpty()); 47 c.clear(); 48 assertTrue(c.isEmpty()); 49 } 50 51 57 public void testClear_1() 58 throws Exception { 59 ChainOfSelectors c = new ChainOfSelectors(); 60 assertEquals(0, c.size()); 61 c.addNaturalSelector(new BestChromosomesSelector(conf)); 62 assertEquals(1, c.size()); 63 assertFalse(c.isEmpty()); 64 c.clear(); 65 assertTrue(c.isEmpty()); 66 } 67 68 74 public void testClear_2() 75 throws Exception { 76 ChainOfSelectors c = new ChainOfSelectors(); 77 Collection l = new Vector(); 78 l.add(new BestChromosomesSelector(conf)); 79 l.add(new WeightedRouletteSelector(conf)); 80 c.addAll(l); 81 assertEquals(2, c.size()); 82 c.clear(); 83 assertTrue(c.isEmpty()); 84 assertEquals(0, c.size()); 85 } 86 87 93 public void testIterator_0() 94 throws Exception { 95 ChainOfSelectors c = new ChainOfSelectors(); 96 Collection l = new Vector(); 97 l.add(new BestChromosomesSelector(conf)); 98 l.add(new WeightedRouletteSelector(conf)); 99 c.addAll(l); 100 Iterator it = c.iterator(); 101 assertTrue(it.hasNext()); 102 assertNotNull(it.next()); 103 assertTrue(it.hasNext()); 104 assertNotNull(it.next()); 105 assertFalse(it.hasNext()); 106 } 107 108 114 public void testAddNaturalSelector_0() 115 throws Exception { 116 ChainOfSelectors c = new ChainOfSelectors(); 117 try { 118 c.addNaturalSelector(null); 119 fail(); 120 } 121 catch (InvalidConfigurationException inex) { 122 ; } 124 } 125 126 public void testEquals_0() 127 throws Exception { 128 ChainOfSelectors c1 = new ChainOfSelectors(); 129 ChainOfSelectors c2 = new ChainOfSelectors(); 130 assertFalse(c1.equals(null)); 131 assertTrue(c1.equals(c2)); 132 TournamentSelector t1 = new TournamentSelector(); 133 c1.addNaturalSelector(t1); 134 assertFalse(c1.equals(c2)); 135 c2.addNaturalSelector(new TournamentSelector()); 136 139 assertFalse(c1.equals(c2)); 140 c2.clear(); 141 c2.addNaturalSelector(t1); 142 assertTrue(c1.equals(c2)); 143 } 144 145 151 public void testEquals_1() 152 throws Exception { 153 ChainOfSelectors c1 = new ChainOfSelectors(); 154 assertFalse(c1.equals(new BooleanGene(conf))); 155 } 156 157 163 public void testHashCode_0() 164 throws Exception { 165 ChainOfSelectors c1 = new ChainOfSelectors(); 166 ChainOfSelectors c2 = new ChainOfSelectors(); 167 assertEquals(c1.hashCode(), c2.hashCode()); 168 c1.addNaturalSelector(new BestChromosomesSelector(conf)); 169 assertFalse(c1.hashCode() == c2.hashCode()); 170 assertEquals(c1.hashCode(), c1.hashCode()); 171 c2.addNaturalSelector(new BestChromosomesSelector(conf)); 172 assertFalse(c1.hashCode() == c2.hashCode()); 173 } 174 } 175 | Popular Tags |