KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > java > lexer > JavaLexerRandomTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.java.lexer;
21
22 import junit.framework.TestCase;
23 import org.netbeans.api.java.lexer.JavaTokenId;
24 import org.netbeans.lib.lexer.test.FixedTextDescriptor;
25 import org.netbeans.lib.lexer.test.RandomCharDescriptor;
26 import org.netbeans.lib.lexer.test.RandomModifyDescriptor;
27 import org.netbeans.lib.lexer.test.RandomTextProvider;
28 import org.netbeans.lib.lexer.test.TestRandomModify;
29
30 /**
31  * Test several simple lexer impls.
32  *
33  * @author mmetelka
34  */

35 public class JavaLexerRandomTest extends TestCase {
36
37     public JavaLexerRandomTest(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     protected void setUp() throws java.lang.Exception JavaDoc {
42         // Set-up testing environment
43
System.setProperty("netbeans.debug.lexer.test", "true");
44     }
45
46     protected void tearDown() throws java.lang.Exception JavaDoc {
47     }
48
49     public void testRandom() throws Exception JavaDoc {
50         test(0);
51     }
52     
53     private void test(long seed) throws Exception JavaDoc {
54         TestRandomModify randomModify = new TestRandomModify(seed);
55         randomModify.setLanguage(JavaTokenId.language());
56         
57         //randomModify.setDebugOperation(true);
58
//randomModify.setDebugDocumentText(true);
59
//randomModify.setDebugHierarchy(true);
60

61         FixedTextDescriptor[] fixedTexts = new FixedTextDescriptor[] {
62             FixedTextDescriptor.create("/**/", 0.2),
63             FixedTextDescriptor.create("*/", 0.2),
64         };
65         
66         RandomCharDescriptor[] regularChars = new RandomCharDescriptor[] {
67             RandomCharDescriptor.letter(0.3),
68             RandomCharDescriptor.space(0.3),
69             RandomCharDescriptor.lf(0.3),
70             RandomCharDescriptor.chars(new char[] { '+', '-', '*', '/'}, 0.3),
71         };
72
73         RandomCharDescriptor[] anyChar = new RandomCharDescriptor[] {
74             RandomCharDescriptor.anyChar(1.0),
75         };
76
77         RandomTextProvider regularTextProvider = new RandomTextProvider(regularChars, fixedTexts);
78         RandomTextProvider anyCharTextProvider = new RandomTextProvider(anyChar, fixedTexts);
79         
80         randomModify.test(
81             new RandomModifyDescriptor[] {
82                 new RandomModifyDescriptor(1000, regularTextProvider,
83                         0.2, 0.2, 0.1,
84                         0.2, 0.2,
85                         0.0, 0.0),
86             }
87         );
88
89         randomModify.test(
90             new RandomModifyDescriptor[] {
91                 new RandomModifyDescriptor(1000, anyCharTextProvider,
92                         0.4, 0.2, 0.2,
93                         0.1, 0.1,
94                         0.0, 0.0),
95                 new RandomModifyDescriptor(1000, anyCharTextProvider,
96                         0.2, 0.2, 0.1,
97                         0.4, 0.3,
98                         0.0, 0.0),
99             }
100         );
101     }
102     
103 }
104
Popular Tags