Source Code Cross Referenced for AbbreviatorTest.java in  » Development » SLF4J » org » slf4j » migrator » helper » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » SLF4J » org.slf4j.migrator.helper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.slf4j.migrator.helper;
002:
003:        import org.slf4j.migrator.helper.Abbreviator;
004:
005:        import junit.framework.TestCase;
006:
007:        public class AbbreviatorTest extends TestCase {
008:
009:            static final char FS = '/';
010:            static final String INPUT_0 = "/abc/123456/ABC";
011:            static final String INPUT_1 = "/abc/123456/xxxxx/ABC";
012:
013:            RandomHelper rh = new RandomHelper(FS);
014:
015:            public AbbreviatorTest(String arg0) {
016:                super (arg0);
017:            }
018:
019:            protected void setUp() throws Exception {
020:                super .setUp();
021:            }
022:
023:            protected void tearDown() throws Exception {
024:                super .tearDown();
025:            }
026:
027:            public void testSmoke() {
028:                {
029:                    Abbreviator abb = new Abbreviator(2, 100, FS);
030:                    String r = abb.abbreviate(INPUT_0);
031:                    assertEquals(INPUT_0, r);
032:                }
033:
034:                {
035:                    Abbreviator abb = new Abbreviator(3, 8, FS);
036:                    String r = abb.abbreviate(INPUT_0);
037:                    assertEquals("/abc/.../ABC", r);
038:                }
039:                {
040:                    Abbreviator abb = new Abbreviator(3, 8, FS);
041:                    String r = abb.abbreviate(INPUT_0);
042:                    assertEquals("/abc/.../ABC", r);
043:                }
044:            }
045:
046:            public void testImpossibleToAbbreviate() {
047:                Abbreviator abb = new Abbreviator(2, 20, FS);
048:                String in = "iczldqwivpgm/mgrmvbjdxrwmqgprdjusth";
049:                String r = abb.abbreviate(in);
050:                assertEquals(in, r);
051:            }
052:
053:            public void testNoFS() {
054:                Abbreviator abb = new Abbreviator(2, 100, FS);
055:                String r = abb.abbreviate("hello");
056:                assertEquals("hello", r);
057:
058:            }
059:
060:            public void testZeroPrefix() {
061:                {
062:                    Abbreviator abb = new Abbreviator(0, 100, FS);
063:                    String r = abb.abbreviate(INPUT_0);
064:                    assertEquals(INPUT_0, r);
065:                }
066:            }
067:
068:            public void testTheories() {
069:                int MAX_RANDOM_FIXED_LEN = 20;
070:                int MAX_RANDOM_AVG_LEN = 20;
071:                int MAX_RANDOM_MAX_LEN = 100;
072:                for (int i = 0; i < 10000; i++) {
073:
074:                    //System.out.println("Test number " + i);
075:
076:                    // 0 <= fixedLen < MAX_RANDOM_FIXED_LEN
077:                    int fixedLen = rh.nextInt(MAX_RANDOM_FIXED_LEN);
078:                    // 5 <= averageLen < MAX_RANDOM_AVG_LEN
079:                    int averageLen = rh.nextInt(MAX_RANDOM_AVG_LEN) + 3;
080:                    // System.out.println("fixedLen="+fixedLen+", averageLen="+averageLen);
081:
082:                    int maxLen = rh.nextInt(MAX_RANDOM_MAX_LEN) + fixedLen;
083:                    if (maxLen <= 1) {
084:                        continue;
085:                    }
086:                    // System.out.println("maxLen="+maxLen);
087:                    int targetLen = (maxLen / 2) + rh.nextInt(maxLen / 2) + 1;
088:
089:                    if (targetLen > maxLen) {
090:                        targetLen = maxLen;
091:                    }
092:                    String filename = rh
093:                            .buildRandomFileName(averageLen, maxLen);
094:
095:                    Abbreviator abb = new Abbreviator(fixedLen, targetLen, FS);
096:                    String result = abb.abbreviate(filename);
097:                    assertTheory0(averageLen, filename, result, fixedLen,
098:                            targetLen);
099:                    assertUsefulness(averageLen, filename, result, fixedLen,
100:                            targetLen);
101:                    assertTheory1(filename, result, fixedLen, targetLen);
102:                    assertTheory2(filename, result, fixedLen, targetLen);
103:                }
104:            }
105:
106:            // result length is smaller than original length 
107:            void assertTheory0(int averageLen, String filename, String result,
108:                    int fixedLen, int targetLength) {
109:                assertTrue("filename=[" + filename + "] result=[" + result
110:                        + "]", result.length() <= filename.length());
111:            }
112:
113:            // if conditions allow, result length should be to target length
114:            void assertUsefulness(int averageLen, String filename,
115:                    String result, int fixedLen, int targetLength) {
116:                int resLen = result.length();
117:
118:                int margin = averageLen * 4;
119:                if (targetLength > fixedLen + margin) {
120:                    assertTrue("filename=[" + filename + "], result=[" + result
121:                            + "] resultLength=" + resLen + " fixedLength="
122:                            + fixedLen + ", targetLength=" + targetLength
123:                            + ", avgLen=" + averageLen,
124:                            result.length() <= targetLength + averageLen);
125:                }
126:            }
127:
128:            // result start with prefix found in filename
129:            void assertTheory1(String filename, String result, int fixedLen,
130:                    int targetLength) {
131:                String prefix = filename.substring(0, fixedLen);
132:                assertTrue(result.startsWith(prefix));
133:            }
134:
135:            // The string /.../ is found in the result once at a position higher
136:            // than fixedLen
137:            void assertTheory2(String filename, String result, int fixedLen,
138:                    int targetLength) {
139:                if (filename == result) {
140:                    return;
141:                }
142:                int fillerIndex = result.indexOf(Abbreviator.FILLER);
143:                assertTrue(fillerIndex >= fixedLen);
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.