KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > supergenes > SupergeneInternalParserTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.supergenes;
11
12 import java.util.*;
13 import org.jgap.*;
14 import junit.framework.*;
15
16 /** Tests the Supergene internal parser. */
17 public class SupergeneInternalParserTest
18     extends JGAPTestCase {
19   /** String containing the CVS revision. Read out via reflection!*/
20   private final static String JavaDoc CVS_REVISION = "$Revision: 1.13 $";
21
22   public static Test suite() {
23     TestSuite suite =
24         new TestSuite(SupergeneInternalParserTest.class);
25     return suite;
26   }
27
28   public void testSupergeneInternalParser()
29       throws Exception JavaDoc {
30     TestClass m_test = new TestClass(conf);
31     /* Undocumented test statements. */
32     String JavaDoc expectedResponse =
33         "----'0'"
34         + "----'1'"
35         + "----'2'"
36         + "----''"
37         + "--------'i1'"
38         + "--------'ib'"
39         + "--------'ic'"
40         + "--------'k1'"
41         + "--------'k2'"
42         + "------------'hn1'"
43         + "----------------''"
44         + "----------------'a'"
45         + "------------'hn2'"
46         + "------------'hn3'";
47     String JavaDoc s = "<0><1><2><><" + m_test.encode("<i1><ib><ic>")
48         + "><" + m_test.encode("<k1><k2><"
49                                + m_test.encode("<hn1><" + m_test.encode("<><a>")
50                                                + "><hn2><hn3>") + ">") + ">";
51     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
52     m_test.splitRecursive(s, b, "", false);
53     assertEquals(b.toString(), expectedResponse);
54   }
55
56   class TestClass
57       extends AbstractSupergene {
58     public TestClass(final Configuration a_conf)
59         throws InvalidConfigurationException {
60       super(a_conf, new Gene[]{});
61     }
62
63     //Used in test only
64
private void splitRecursive(String JavaDoc a_t, StringBuffer JavaDoc a_buffer,
65                                 String JavaDoc a_ident, boolean a_print)
66         throws UnsupportedRepresentationException {
67       if (a_t.indexOf(GENE_DELIMITER_HEADING) < 0) {
68         String JavaDoc p = a_ident + "'" + a_t + "'";
69         if (a_print) {
70           System.out.println(p);
71         }
72         a_buffer.append(p);
73       }
74       else {
75         Iterator iter = split(a_t).iterator();
76         while (iter.hasNext()) {
77           String JavaDoc item = (String JavaDoc) iter.next();
78           item = decode(item);
79           splitRecursive(item, a_buffer, a_ident + "----", a_print);
80         }
81       }
82     }
83
84     public boolean isValid(Gene[] a) {
85       throw new Error JavaDoc("Should never be called.");
86     }
87
88     protected Gene newGeneInternal() {
89       throw new Error JavaDoc("Should never be called.");
90     }
91   }
92 }
93
Popular Tags