Source Code Cross Referenced for TextTrieMapTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » util » 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 » Internationalization Localization » icu4j » com.ibm.icu.dev.test.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2006, International Business Machines Corporation and         *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.dev.test.util;
008:
009:        import com.ibm.icu.dev.test.TestFmwk;
010:        import com.ibm.icu.impl.TextTrieMap;
011:
012:        public class TextTrieMapTest extends TestFmwk {
013:
014:            private static final Integer SUN = new Integer(1);
015:            private static final Integer MON = new Integer(2);
016:            private static final Integer TUE = new Integer(3);
017:            private static final Integer WED = new Integer(4);
018:            private static final Integer THU = new Integer(5);
019:            private static final Integer FRI = new Integer(6);
020:            private static final Integer SAT = new Integer(7);
021:
022:            private static final Integer FOO = new Integer(-1);
023:            private static final Integer BAR = new Integer(-2);
024:
025:            private static final Object[][] TESTDATA = { { "Sunday", SUN },
026:                    { "Monday", MON }, { "Tuesday", TUE },
027:                    { "Wednesday", WED }, { "Thursday", THU },
028:                    { "Friday", FRI }, { "Saturday", SAT }, { "Sun", SUN },
029:                    { "Mon", MON }, { "Tue", TUE }, { "Wed", WED },
030:                    { "Thu", THU }, { "Fri", FRI }, { "Sat", SAT },
031:                    { "S", SUN }, { "M", MON }, { "T", TUE }, { "W", WED },
032:                    { "T", THU }, { "F", FRI }, { "S", SAT } };
033:
034:            private static final Object[][] TESTCASES = {
035:                    { "Sunday", SUN, SUN }, { "sunday", null, SUN },
036:                    { "Mo", MON, MON }, { "mo", null, MON },
037:                    { "Thursday Friday", THU, THU }, { "T", THU, THU },
038:                    { "TEST", THU, THU }, { "SUN", SAT, SUN },
039:                    { "super", null, SAT }, { "NO", null, null } };
040:
041:            public static void main(String[] args) throws Exception {
042:                TextTrieMapTest test = new TextTrieMapTest();
043:                test.run(args);
044:            }
045:
046:            public void TestCaseSensitive() {
047:                TextTrieMap map = new TextTrieMap(false);
048:                for (int i = 0; i < TESTDATA.length; i++) {
049:                    map.put((String) TESTDATA[i][0], TESTDATA[i][1]);
050:                }
051:
052:                logln("Test for get(String)");
053:                for (int i = 0; i < TESTCASES.length; i++) {
054:                    Object value = map.get((String) TESTCASES[i][0]);
055:                    if (!eql(value, TESTCASES[i][1])) {
056:                        errln("Invalid search results - Expected:"
057:                                + TESTCASES[i][1] + " Actual:" + value);
058:                    }
059:                }
060:
061:                logln("Test for get(String, int)");
062:                StringBuffer textBuf = new StringBuffer();
063:                for (int i = 0; i < TESTCASES.length; i++) {
064:                    textBuf.setLength(0);
065:                    for (int j = 0; j < i; j++) {
066:                        textBuf.append('X');
067:                    }
068:                    textBuf.append(TESTCASES[i][0]);
069:                    Object value = map.get(textBuf.toString(), i);
070:                    if (!eql(value, TESTCASES[i][1])) {
071:                        errln("Invalid search results - Expected:"
072:                                + TESTCASES[i][1] + " Actual:" + value);
073:                    }
074:                }
075:
076:                // Add duplicated entry
077:                Object prev = map.put("Sunday", FOO);
078:                if (!eql(prev, SUN)) {
079:                    errln("The previous value of duplicated entry is not valid - Expected:"
080:                            + SUN + " Actual:" + prev);
081:                }
082:                // Make sure the value is updated
083:                Object value = map.get("Sunday");
084:                if (!eql(value, FOO)) {
085:                    errln("The map value is not valid - Expected:" + FOO
086:                            + " Actual:" + value);
087:                }
088:
089:                // Add duplicated entry with different casing
090:                prev = map.put("sunday", BAR);
091:                if (!eql(prev, null)) {
092:                    errln("The value should be new in the trie map - Expected:null"
093:                            + " Actual:" + prev);
094:                }
095:                // Make sure the value is valid
096:                value = map.get("sunday");
097:                if (!eql(value, BAR)) {
098:                    errln("The map value is not valid - Expected:" + BAR
099:                            + " Actual:" + value);
100:                }
101:
102:            }
103:
104:            public void TestCaseInsensitive() {
105:                TextTrieMap map = new TextTrieMap(true);
106:                for (int i = 0; i < TESTDATA.length; i++) {
107:                    map.put((String) TESTDATA[i][0], TESTDATA[i][1]);
108:                }
109:
110:                logln("Test for get(String)");
111:                for (int i = 0; i < TESTCASES.length; i++) {
112:                    Object value = map.get((String) TESTCASES[i][0]);
113:                    if (!eql(value, TESTCASES[i][2])) {
114:                        errln("Invalid search results - Expected:"
115:                                + TESTCASES[i][2] + " Actual:" + value);
116:                    }
117:                }
118:
119:                logln("Test for get(String, int)");
120:                StringBuffer textBuf = new StringBuffer();
121:                for (int i = 0; i < TESTCASES.length; i++) {
122:                    textBuf.setLength(0);
123:                    for (int j = 0; j < i; j++) {
124:                        textBuf.append('X');
125:                    }
126:                    textBuf.append(TESTCASES[i][0]);
127:                    Object value = map.get(textBuf.toString(), i);
128:                    if (!eql(value, TESTCASES[i][2])) {
129:                        errln("Invalid search results - Expected:"
130:                                + TESTCASES[i][2] + " Actual:" + value);
131:                    }
132:                }
133:
134:                // Add duplicated entry
135:                Object prev = map.put("Sunday", FOO);
136:                if (!eql(prev, SUN)) {
137:                    errln("The previous value of duplicated entry is not valid - Expected:"
138:                            + SUN + " Actual:" + prev);
139:                }
140:                // Make sure the value is updated
141:                Object value = map.get("Sunday");
142:                if (!eql(value, FOO)) {
143:                    errln("The map value is not valid - Expected:" + FOO
144:                            + " Actual:" + value);
145:                }
146:
147:                // Add duplicated entry with different casing
148:                prev = map.put("sunday", BAR);
149:                if (!eql(prev, FOO)) {
150:                    errln("The value should be new in the trie map - Expected:"
151:                            + FOO + " Actual:" + prev);
152:                }
153:                // Make sure the value is updated
154:                value = map.get("sunday");
155:                if (!eql(value, BAR)) {
156:                    errln("The map value is not valid - Expected:" + BAR
157:                            + " Actual:" + value);
158:                }
159:
160:            }
161:
162:            private boolean eql(Object o1, Object o2) {
163:                if (o1 == null || o2 == null) {
164:                    if (o1 == null && o2 == null) {
165:                        return true;
166:                    }
167:                    return false;
168:                }
169:                return o1.equals(o2);
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.