1 10 package org.jgap.supergenes; 11 12 import java.util.*; 13 import org.jgap.*; 14 import junit.framework.*; 15 16 17 public class SupergeneInternalParserTest 18 extends JGAPTestCase { 19 20 private final static String 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 { 30 TestClass m_test = new TestClass(conf); 31 32 String 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 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 b = new StringBuffer (); 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 private void splitRecursive(String a_t, StringBuffer a_buffer, 65 String a_ident, boolean a_print) 66 throws UnsupportedRepresentationException { 67 if (a_t.indexOf(GENE_DELIMITER_HEADING) < 0) { 68 String 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 item = (String ) 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 ("Should never be called."); 86 } 87 88 protected Gene newGeneInternal() { 89 throw new Error ("Should never be called."); 90 } 91 } 92 } 93 | Popular Tags |