Test of increment method, of class IntDoubleMap.
()
| 235 | * Test of increment method, of class IntDoubleMap. |
| 236 | */ |
| 237 | @Test |
| 238 | public void testIncrement() |
| 239 | { |
| 240 | System.out.println("increment"); |
| 241 | Integer key = null; |
| 242 | Double value = null; |
| 243 | |
| 244 | Map<Integer, Double> truthMap = new HashMap<Integer, Double>(); |
| 245 | IntDoubleMap idMap = new IntDoubleMap(); |
| 246 | |
| 247 | int MAX = TEST_SIZE/2; |
| 248 | int times =0; |
| 249 | for(int i = 0; i < MAX; i++) |
| 250 | { |
| 251 | key = Integer.valueOf(rand.nextInt(MAX)); |
| 252 | value = Double.valueOf(rand.nextInt(1000)); |
| 253 | if(truthMap.containsKey(key)) |
| 254 | times++; |
| 255 | Double prevTruth = truthMap.put(key, value); |
| 256 | Double prev = idMap.put(key, value); |
| 257 | |
| 258 | if(prev == null && prevTruth != null) |
| 259 | System.out.println(idMap.put(key, value)); |
| 260 | assertEquals(prevTruth, prev); |
| 261 | if(idMap.size() != truthMap.size()) |
| 262 | { |
| 263 | System.out.println(); |
| 264 | } |
| 265 | assertEquals(truthMap.size(), idMap.size()); |
| 266 | } |
| 267 | |
| 268 | assertEntriesAreEqual(truthMap, idMap); |
| 269 | |
| 270 | for(Entry<Integer, Double> entry : truthMap.entrySet()) |
| 271 | { |
| 272 | double delta = Double.valueOf(rand.nextInt(100)); |
| 273 | double trueNewValue =entry.getValue()+delta; |
| 274 | entry.setValue(trueNewValue); |
| 275 | double newValue = idMap.increment(entry.getKey(), delta); |
| 276 | assertEquals(trueNewValue, newValue, 0.0); |
| 277 | } |
| 278 | |
| 279 | for(int i = MAX; i < MAX*2; i++) |
| 280 | { |
| 281 | key = Integer.valueOf(i);//force it to be new |
| 282 | value = Double.valueOf(rand.nextInt(1000)); |
| 283 | |
| 284 | truthMap.put(key, value); |
| 285 | double ldNew =idMap.increment(key, value); |
| 286 | assertEquals(value.doubleValue(), ldNew, 0.0); |
| 287 | } |
| 288 | |
| 289 | assertEntriesAreEqual(truthMap, idMap); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Test of remove method, of class IntDoubleMap. |
nothing calls this directly
no test coverage detected