예제 #1
0
 private OpenIntToFieldHashMap<Fraction> createFromJavaMap(Field<Fraction> field) {
   OpenIntToFieldHashMap<Fraction> map = new OpenIntToFieldHashMap<Fraction>(field);
   for (Map.Entry<Integer, Fraction> mapEntry : javaMap.entrySet()) {
     map.put(mapEntry.getKey(), mapEntry.getValue());
   }
   return map;
 }
예제 #2
0
  /**
   * Similar to testPutKeysWithCollisions() but exercises the codepaths in a slightly different
   * manner.
   */
  @Test
  public void testPutKeysWithCollision2() {
    OpenIntToFieldHashMap<Fraction> map = new OpenIntToFieldHashMap<Fraction>(field);
    int key1 = 837989881;
    Fraction value1 = new Fraction(1);
    map.put(key1, value1);
    int key2 = 476463321;
    map.put(key2, value1);
    Assert.assertEquals(2, map.size());
    Assert.assertEquals(value1, map.get(key2));

    map.remove(key1);
    Fraction value2 = new Fraction(2);
    map.put(key2, value2);
    Assert.assertEquals(1, map.size());
    Assert.assertEquals(value2, map.get(key2));
  }
예제 #3
0
 @Test
 public void testPutOnExisting() {
   OpenIntToFieldHashMap<Fraction> map = createFromJavaMap(field);
   for (Map.Entry<Integer, Fraction> mapEntry : javaMap.entrySet()) {
     map.put(mapEntry.getKey(), mapEntry.getValue());
     Assert.assertEquals(javaMap.size(), map.size());
     Assert.assertEquals(mapEntry.getValue(), map.get(mapEntry.getKey()));
   }
 }
예제 #4
0
  /**
   * Regression test for a bug in findInsertionIndex where the hashing in the second probing loop
   * was inconsistent with the first causing duplicate keys after the right sequence of puts and
   * removes.
   */
  @Test
  public void testPutKeysWithCollisions() {
    OpenIntToFieldHashMap<Fraction> map = new OpenIntToFieldHashMap<Fraction>(field);
    int key1 = -1996012590;
    Fraction value1 = new Fraction(1);
    map.put(key1, value1);
    int key2 = 835099822;
    map.put(key2, value1);
    int key3 = 1008859686;
    map.put(key3, value1);
    Assert.assertEquals(value1, map.get(key3));
    Assert.assertEquals(3, map.size());

    map.remove(key2);
    Fraction value2 = new Fraction(2);
    map.put(key3, value2);
    Assert.assertEquals(value2, map.get(key3));
    Assert.assertEquals(2, map.size());
  }
예제 #5
0
 private void assertPutAndGet(
     OpenIntToFieldHashMap<Fraction> map, int mapSize, Set<Integer> keysInMap) {
   Assert.assertEquals(mapSize, map.size());
   for (Map.Entry<Integer, Fraction> mapEntry : javaMap.entrySet()) {
     map.put(mapEntry.getKey(), mapEntry.getValue());
     if (!keysInMap.contains(mapEntry.getKey())) ++mapSize;
     Assert.assertEquals(mapSize, map.size());
     Assert.assertEquals(mapEntry.getValue(), map.get(mapEntry.getKey()));
   }
 }
예제 #6
0
 @Test
 public void testConcurrentModification() {
   OpenIntToFieldHashMap<Fraction> map = createFromJavaMap(field);
   OpenIntToFieldHashMap<Fraction>.Iterator iterator = map.iterator();
   map.put(3, new Fraction(3));
   try {
     iterator.advance();
     Assert.fail("an exception should have been thrown");
   } catch (ConcurrentModificationException cme) {
     // expected
   }
 }