1 36 package org.columba.ristretto.parser; 37 38 import java.util.List ; 39 import java.util.Random ; 40 41 import junit.framework.TestCase; 42 43 public class CharSequenceSearcherTest extends TestCase { 44 45 public void test1() { 46 String pattern = "ababababca"; 47 CharSequenceSearcher searcher = new CharSequenceSearcher(pattern.toCharArray()); 48 49 int[] positions = { 100, 200, 5234 }; 50 Random random = new Random (); 51 52 StringBuffer testText = new StringBuffer (); 54 for( int i=0; i<positions.length; i++) { 55 for(int j=testText.length(); j<positions[i]; j++) { 56 testText.append((char)(random.nextInt() & 0x0ff)); 57 } 58 59 testText.append(pattern); 60 } 61 62 List result = searcher.match(testText); 63 for( int i=0; i<positions.length; i++) { 64 assertEquals(positions[i], ((Integer )result.get(i)).intValue()); 65 } 66 67 68 } 69 70 71 72 } 73 | Popular Tags |