Source Code Cross Referenced for P2PHashMapTest.java in  » Development » trove » gnu » trove » 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 » trove » gnu.trove 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright(c) 2006, NEXVU Technologies
003:         * All rights reserved.
004:         */
005:        package gnu.trove;
006:
007:        import gnu.trove.decorator.TByteIntHashMapDecorator;
008:        import junit.framework.TestCase;
009:
010:        import java.util.Iterator;
011:        import java.util.Map;
012:        import java.util.Set;
013:
014:        /**
015:         *
016:         */
017:        public class P2PHashMapTest extends TestCase {
018:            final byte KEY_ONE = (byte) 100;
019:            final byte KEY_TWO = (byte) 101;
020:
021:            public P2PHashMapTest(String name) {
022:                super (name);
023:            }
024:
025:            public void testKeys() {
026:                TByteIntHashMap map = new TByteIntHashMap();
027:
028:                map.put(KEY_ONE, 1);
029:                map.put(KEY_TWO, 2);
030:
031:                assertEquals(2, map.size());
032:
033:                byte[] keys = map.keys(new byte[map.size()]);
034:                assertEquals(2, keys.length);
035:                TByteArrayList keys_list = new TByteArrayList(keys);
036:
037:                assertTrue(keys_list.contains(KEY_ONE));
038:                assertTrue(keys_list.contains(KEY_TWO));
039:
040:                byte[] keys2 = map.keys();
041:                assertEquals(2, keys2.length);
042:                TByteArrayList keys_list2 = new TByteArrayList(keys2);
043:
044:                assertTrue(keys_list2.contains(KEY_ONE));
045:                assertTrue(keys_list2.contains(KEY_TWO));
046:            }
047:
048:            public void testDecorator() {
049:                TByteIntHashMap map = new TByteIntHashMap();
050:
051:                map.put(KEY_ONE, 1);
052:                map.put(KEY_TWO, 2);
053:
054:                Map<Byte, Integer> decorator = new TByteIntHashMapDecorator(map);
055:
056:                assertEquals(2, decorator.size());
057:                assertEquals(Integer.valueOf(1), decorator.get(Byte
058:                        .valueOf(KEY_ONE)));
059:                assertEquals(Integer.valueOf(2), decorator.get(Byte
060:                        .valueOf(KEY_TWO)));
061:
062:                Set<Byte> decorator_keys = decorator.keySet();
063:                assertEquals(2, decorator_keys.size());
064:                Iterator<Byte> it = decorator_keys.iterator();
065:                int count = 0;
066:                while (it.hasNext()) {
067:                    count++;
068:                    System.out.println(it.next());
069:                }
070:                assertEquals(2, count);
071:
072:                assertSame(map, ((TByteIntHashMapDecorator) decorator).getMap());
073:            }
074:
075:            public void testIterator() {
076:                TByteIntHashMap map = new TByteIntHashMap();
077:
078:                TByteIntIterator iterator = map.iterator();
079:                assertFalse(iterator.hasNext());
080:
081:                map.put(KEY_ONE, 1);
082:                map.put(KEY_TWO, 2);
083:
084:                iterator = map.iterator();
085:                assertTrue(iterator.hasNext());
086:                iterator.advance();
087:                assertTrue(iterator.hasNext());
088:                iterator.advance();
089:                assertFalse(iterator.hasNext());
090:            }
091:
092:            public void testAdjustValue() {
093:                TByteIntHashMap map = new TByteIntHashMap();
094:
095:                map.put(KEY_ONE, 1);
096:
097:                boolean changed = map.adjustValue(KEY_ONE, 1);
098:                assertTrue(changed);
099:                assertEquals(2, map.get(KEY_ONE));
100:
101:                changed = map.adjustValue(KEY_ONE, 5);
102:                assertTrue(changed);
103:                assertEquals(7, map.get(KEY_ONE));
104:
105:                changed = map.adjustValue(KEY_ONE, -3);
106:                assertTrue(changed);
107:                assertEquals(4, map.get(KEY_ONE));
108:
109:                changed = map.adjustValue(KEY_TWO, 1);
110:                assertFalse(changed);
111:                assertFalse(map.containsKey(KEY_TWO));
112:            }
113:
114:            public void testAdjustOrPutValue() {
115:                TByteIntHashMap map = new TByteIntHashMap();
116:
117:                map.put(KEY_ONE, 1);
118:
119:                long new_value = map.adjustOrPutValue(KEY_ONE, 1, 100);
120:                assertEquals(2, new_value);
121:                assertEquals(2, map.get(KEY_ONE));
122:
123:                new_value = map.adjustOrPutValue(KEY_ONE, 5, 100);
124:                assertEquals(7, new_value);
125:                assertEquals(7, map.get(KEY_ONE));
126:
127:                new_value = map.adjustOrPutValue(KEY_ONE, -3, 100);
128:                assertEquals(4, new_value);
129:                assertEquals(4, map.get(KEY_ONE));
130:
131:                new_value = map.adjustOrPutValue(KEY_TWO, 1, 100);
132:                assertEquals(100, new_value);
133:                assertTrue(map.containsKey(KEY_TWO));
134:                assertEquals(100, map.get(KEY_TWO));
135:
136:                new_value = map.adjustOrPutValue(KEY_TWO, 1, 100);
137:                assertEquals(101, new_value);
138:                assertEquals(101, map.get(KEY_TWO));
139:            }
140:
141:            /**
142:             * Test for tracking issue #1204014. +0.0 and -0.0 have different bit patterns, but
143:             * should be counted the same as keys in a map. Checks for doubles and floats.
144:             */
145:            public void testFloatZeroHashing() {
146:                TDoubleObjectHashMap<String> po_double_map = new TDoubleObjectHashMap<String>();
147:                TDoubleIntHashMap pp_double_map = new TDoubleIntHashMap();
148:                TFloatObjectHashMap<String> po_float_map = new TFloatObjectHashMap<String>();
149:                TFloatIntHashMap pp_float_map = new TFloatIntHashMap();
150:
151:                final double zero_double = 0.0;
152:                final double negative_zero_double = -zero_double;
153:                final float zero_float = 0.0f;
154:                final float negative_zero_float = -zero_float;
155:
156:                // Sanity check... make sure I'm really creating two different values.
157:                final String zero_bits_double = Long.toBinaryString(Double
158:                        .doubleToLongBits(zero_double));
159:                final String negative_zero_bits_double = Long
160:                        .toBinaryString(Double
161:                                .doubleToLongBits(negative_zero_double));
162:                assertFalse(zero_bits_double + " == "
163:                        + negative_zero_bits_double, zero_bits_double
164:                        .equals(negative_zero_bits_double));
165:
166:                final String zero_bits_float = Integer.toBinaryString(Float
167:                        .floatToIntBits(zero_float));
168:                final String negative_zero_bits_float = Integer
169:                        .toBinaryString(Float
170:                                .floatToIntBits(negative_zero_float));
171:                assertFalse(
172:                        zero_bits_float + " == " + negative_zero_bits_float,
173:                        zero_bits_float.equals(negative_zero_bits_float));
174:
175:                po_double_map.put(zero_double, "Zero");
176:                po_double_map.put(negative_zero_double, "Negative Zero");
177:
178:                pp_double_map.put(zero_double, 0);
179:                pp_double_map.put(negative_zero_double, -1);
180:
181:                po_float_map.put(zero_float, "Zero");
182:                po_float_map.put(negative_zero_float, "Negative Zero");
183:
184:                pp_float_map.put(zero_float, 0);
185:                pp_float_map.put(negative_zero_float, -1);
186:
187:                assertEquals(1, po_double_map.size());
188:                assertEquals(po_double_map.get(zero_double), "Negative Zero");
189:                assertEquals(po_double_map.get(negative_zero_double),
190:                        "Negative Zero");
191:
192:                assertEquals(1, pp_double_map.size());
193:                assertEquals(pp_double_map.get(zero_double), -1);
194:                assertEquals(pp_double_map.get(negative_zero_double), -1);
195:
196:                assertEquals(1, po_float_map.size());
197:                assertEquals(po_float_map.get(zero_float), "Negative Zero");
198:                assertEquals(po_float_map.get(negative_zero_float),
199:                        "Negative Zero");
200:
201:                assertEquals(1, pp_float_map.size());
202:                assertEquals(pp_float_map.get(zero_float), -1);
203:                assertEquals(pp_float_map.get(negative_zero_float), -1);
204:
205:                po_double_map.put(zero_double, "Zero");
206:                pp_double_map.put(zero_double, 0);
207:                po_float_map.put(zero_float, "Zero");
208:                pp_float_map.put(zero_float, 0);
209:
210:                assertEquals(1, po_double_map.size());
211:                assertEquals(po_double_map.get(zero_double), "Zero");
212:                assertEquals(po_double_map.get(negative_zero_double), "Zero");
213:
214:                assertEquals(1, pp_double_map.size());
215:                assertEquals(pp_double_map.get(zero_double), 0);
216:                assertEquals(pp_double_map.get(negative_zero_double), 0);
217:
218:                assertEquals(1, po_float_map.size());
219:                assertEquals(po_float_map.get(zero_float), "Zero");
220:                assertEquals(po_float_map.get(negative_zero_float), "Zero");
221:
222:                assertEquals(1, pp_float_map.size());
223:                assertEquals(pp_float_map.get(zero_float), 0);
224:                assertEquals(pp_float_map.get(negative_zero_float), 0);
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.