Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/index/file/IntArrayToIntMapTest.java

Issue 371913004: Version 1.5.6 (Closed) Base URL: http://dart.googlecode.com/svn/branches/1.5/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014, the Dart project authors.
3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
11 * or implied. See the License for the specific language governing permissions a nd limitations under
12 * the License.
13 */
14 package com.google.dart.engine.internal.index.file;
15
16 import junit.framework.TestCase;
17
18 public class IntArrayToIntMapTest extends TestCase {
19 private static int[] HASH_32_KEY_1 = {1};
20 private static int[] HASH_32_KEY_2 = {33};
21 private static int[] HASH_32_KEY_3 = {65};
22 private static int[] HASH_33_KEY = {2};
23 private IntArrayToIntMap map = new IntArrayToIntMap(16, 0.75f);
24
25 public void test_get_no() throws Exception {
26 assertEquals(-1, map.get(HASH_32_KEY_1, -1));
27 }
28
29 public void test_put_conflict_3() throws Exception {
30 map.put(HASH_32_KEY_1, 10);
31 map.put(HASH_32_KEY_2, 20);
32 map.put(HASH_32_KEY_3, 30);
33 assertEquals(10, map.get(HASH_32_KEY_1, -1));
34 assertEquals(20, map.get(HASH_32_KEY_2, -1));
35 assertEquals(30, map.get(HASH_32_KEY_3, -1));
36 // update exiting Entry
37 map.put(HASH_32_KEY_2, 200);
38 assertEquals(10, map.get(HASH_32_KEY_1, -1));
39 assertEquals(200, map.get(HASH_32_KEY_2, -1));
40 assertEquals(30, map.get(HASH_32_KEY_3, -1));
41 }
42
43 public void test_put_noConflict() throws Exception {
44 map.put(HASH_32_KEY_1, 10);
45 map.put(HASH_33_KEY, 20);
46 assertEquals(10, map.get(HASH_32_KEY_1, -1));
47 assertEquals(20, map.get(HASH_33_KEY, -1));
48 }
49
50 public void test_remove_hasConflict() throws Exception {
51 // put
52 assertEquals(-1, map.remove(HASH_32_KEY_1, -1));
53 assertEquals(-1, map.remove(HASH_32_KEY_2, -1));
54 assertEquals(-1, map.remove(HASH_32_KEY_3, -1));
55 map.put(HASH_32_KEY_1, 10);
56 map.put(HASH_32_KEY_2, 20);
57 map.put(HASH_32_KEY_3, 30);
58 assertEquals(3, map.size());
59 // remove
60 assertEquals(10, map.remove(HASH_32_KEY_1, -1));
61 assertEquals(2, map.size());
62 assertEquals(20, map.remove(HASH_32_KEY_2, -1));
63 assertEquals(1, map.size());
64 assertEquals(30, map.remove(HASH_32_KEY_3, -1));
65 assertEquals(0, map.size());
66 // nothing to remove
67 assertEquals(-1, map.remove(HASH_32_KEY_1, -1));
68 assertEquals(-1, map.remove(HASH_32_KEY_2, -1));
69 assertEquals(-1, map.remove(HASH_32_KEY_3, -1));
70 assertEquals(0, map.size());
71 }
72
73 public void test_remove_noConflict() throws Exception {
74 assertEquals(-1, map.remove(HASH_32_KEY_1, -1));
75 // put
76 map.put(HASH_32_KEY_1, 10);
77 assertEquals(1, map.size());
78 // remove
79 assertEquals(10, map.remove(HASH_32_KEY_1, -1));
80 assertEquals(-1, map.remove(HASH_32_KEY_1, -1));
81 assertEquals(0, map.size());
82 }
83
84 public void test_size() throws Exception {
85 // empty
86 assertEquals(0, map.size());
87 // 1 key
88 map.put(new int[] {1}, 10);
89 assertEquals(1, map.size());
90 // 2 keys
91 map.put(new int[] {1, 2}, 20);
92 assertEquals(2, map.size());
93 // same key
94 map.put(new int[] {1, 2}, 200);
95 assertEquals(2, map.size());
96 // remove
97 map.remove(new int[] {1, 2}, -1);
98 assertEquals(1, map.size());
99 }
100
101 public void test_stress() throws Exception {
102 int count = 1000;
103 // fill map
104 for (int i = 0; i < count; i++) {
105 int[] key = new int[] {i << 5, i << 3};
106 map.put(key, i);
107 }
108 // check map
109 assertEquals(count, map.size());
110 for (int i = 0; i < count; i++) {
111 int[] key = new int[] {i << 5, i << 3};
112 assertEquals(i, map.get(key, -1));
113 }
114 }
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698