1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.math.genetics;
18
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import org.junit.Test;
24
25 public class BinaryChromosomeTest {
26
27 @Test
28 public void testInvalidConstructor() {
29 Integer[][] reprs = new Integer[][] {
30 new Integer[] {0,1,0,1,2},
31 new Integer[] {0,1,0,1,-1}
32 };
33
34 for (Integer[] repr : reprs) {
35 try {
36 new DummyBinaryChromosome(repr);
37 fail("Exception not caught");
38 } catch (IllegalArgumentException e) {
39
40 }
41 }
42 }
43
44 @Test
45 public void testRandomConstructor() {
46 for (int i=0; i<20; i++) {
47 new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(10));
48 }
49 }
50
51 @Test
52 public void testIsSame() {
53 Chromosome c1 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,1});
54 Chromosome c2 = new DummyBinaryChromosome(new Integer[] {0,1,1,0,1});
55 Chromosome c3 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,1,1});
56 Chromosome c4 = new DummyBinaryChromosome(new Integer[] {1,1,0,1,0,1});
57 Chromosome c5 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,0});
58 Chromosome c6 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,1});
59
60 assertFalse(c1.isSame(c2));
61 assertFalse(c1.isSame(c3));
62 assertFalse(c1.isSame(c4));
63 assertFalse(c1.isSame(c5));
64 assertTrue(c1.isSame(c6));
65 }
66
67 }