1 19 20 package org.netbeans.modules.lexer.editorbridge.calc.lang; 21 22 import junit.framework.TestCase; 23 import org.netbeans.lib.lexer.test.FixedTextDescriptor; 24 import org.netbeans.lib.lexer.test.RandomCharDescriptor; 25 import org.netbeans.lib.lexer.test.RandomModifyDescriptor; 26 import org.netbeans.lib.lexer.test.RandomTextProvider; 27 import org.netbeans.lib.lexer.test.TestRandomModify; 28 29 34 public class CalcLexerRandomTest extends TestCase { 35 36 public CalcLexerRandomTest(String testName) { 37 super(testName); 38 } 39 40 protected void setUp() throws java.lang.Exception { 41 System.setProperty("netbeans.debug.lexer.test", "true"); 43 } 44 45 protected void tearDown() throws java.lang.Exception { 46 } 47 48 public void testRandom() throws Exception { 49 test(0); 50 } 51 52 private void test(long seed) throws Exception { 53 TestRandomModify randomModify = new TestRandomModify(seed); 54 randomModify.setLanguage(CalcTokenId.language()); 55 56 60 FixedTextDescriptor[] fixedTexts = new FixedTextDescriptor[] { 61 FixedTextDescriptor.create("pi", 0.2), 62 }; 63 64 RandomCharDescriptor[] regularChars = new RandomCharDescriptor[] { 65 RandomCharDescriptor.space(0.3), 66 RandomCharDescriptor.lf(0.3), 67 RandomCharDescriptor.digit(0.3), 68 RandomCharDescriptor.chars(new char[] { 69 'e', '+', '-', '*', '/', '(', ')' }, 0.3), 70 RandomCharDescriptor.chars(new char[] { 71 'x', 'i', 'p'}, 0.05), 72 }; 73 74 RandomCharDescriptor[] anyChar = new RandomCharDescriptor[] { 75 RandomCharDescriptor.anyChar(1.0), 76 }; 77 78 RandomTextProvider regularTextProvider = new RandomTextProvider(regularChars, fixedTexts); 79 RandomTextProvider anyCharTextProvider = new RandomTextProvider(anyChar, fixedTexts); 80 81 randomModify.test( 82 new RandomModifyDescriptor[] { 83 new RandomModifyDescriptor(300, regularTextProvider, 84 0.2, 0.2, 0.1, 85 0.2, 0.2, 86 0.0, 0.0), 87 } 88 ); 89 90 randomModify.test( 91 new RandomModifyDescriptor[] { 92 new RandomModifyDescriptor(300, anyCharTextProvider, 93 0.4, 0.2, 0.2, 94 0.1, 0.1, 95 0.0, 0.0), 96 new RandomModifyDescriptor(300, anyCharTextProvider, 97 0.2, 0.2, 0.1, 98 0.4, 0.3, 99 0.0, 0.0), 100 } 101 ); 102 } 103 104 } 105 | Popular Tags |