KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > lexer > editorbridge > calc > lang > CalcLexerRandomTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
30  * Test several simple lexer impls.
31  *
32  * @author mmetelka
33  */

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

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