MCPcopy Index your code
hub / github.com/EdwardRaff/JSAT / testIncrement

Method testIncrement

JSAT/test/jsat/utils/IntDoubleMapTest.java:237–290  ·  view source on GitHub ↗

Test of increment method, of class IntDoubleMap.

()

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 10

putMethod · 0.95
sizeMethod · 0.95
assertEntriesAreEqualMethod · 0.95
incrementMethod · 0.95
sizeMethod · 0.65
containsKeyMethod · 0.45
entrySetMethod · 0.45
getValueMethod · 0.45
setValueMethod · 0.45
getKeyMethod · 0.45

Tested by

no test coverage detected