Skip to content

Commit

Permalink
Fixed missing test coverage for ObjectBooleanHashMapWithHashingStrategy.
Browse files Browse the repository at this point in the history
Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
  • Loading branch information
donraab committed Aug 18, 2020
1 parent 1e0b26e commit dacbcf8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,23 @@ public void toArray()
Assert.assertTrue(Arrays.equals(new boolean[]{false}, map3.toArray()));
}

@Test
public void toArrayWithTargetArray()
{
ObjectBooleanMap<String> map1 = this.newWithKeysValues(null, true, "1", false);
ObjectBooleanMap<String> map2 = this.newWithKeysValues("0", true);
ObjectBooleanMap<String> map3 = this.newWithKeysValues("0", false);

Assert.assertTrue(Arrays.equals(new boolean[]{true, false}, map1.toArray(new boolean[]{}))
|| Arrays.equals(new boolean[]{false, true}, map1.toArray(new boolean[]{})));
Assert.assertTrue(Arrays.equals(new boolean[]{true, false}, map1.toArray(new boolean[map1.size()]))
|| Arrays.equals(new boolean[]{false, true}, map1.toArray(new boolean[map1.size()])));
Assert.assertTrue(Arrays.equals(new boolean[]{true}, map2.toArray(new boolean[]{})));
Assert.assertTrue(Arrays.equals(new boolean[]{true}, map2.toArray(new boolean[map2.size()])));
Assert.assertTrue(Arrays.equals(new boolean[]{false}, map3.toArray(new boolean[]{})));
Assert.assertTrue(Arrays.equals(new boolean[]{false}, map3.toArray(new boolean[map3.size()])));
}

@Test
public void contains()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,58 +162,58 @@ public void putWithRehash() throws Exception
@Test
public void getIfAbsentPut()
{
ObjectBooleanHashMap<Integer> map1 = ObjectBooleanHashMap.newMap();
MutableObjectBooleanMap<Integer> map1 = this.getEmptyMap();
Assert.assertTrue(map1.getIfAbsentPut(0, true));
Assert.assertTrue(map1.getIfAbsentPut(0, false));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, true), map1);
Assert.assertEquals(this.newWithKeysValues(0, true), map1);
Assert.assertTrue(map1.getIfAbsentPut(1, true));
Assert.assertTrue(map1.getIfAbsentPut(1, false));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, true, 1, true), map1);
Assert.assertEquals(this.newWithKeysValues(0, true, 1, true), map1);

ObjectBooleanHashMap<Integer> map2 = ObjectBooleanHashMap.newMap();
MutableObjectBooleanMap<Integer> map2 = this.getEmptyMap();
Assert.assertFalse(map2.getIfAbsentPut(1, false));
Assert.assertFalse(map2.getIfAbsentPut(1, true));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(1, false), map2);
Assert.assertEquals(this.newWithKeysValues(1, false), map2);
Assert.assertFalse(map2.getIfAbsentPut(0, false));
Assert.assertFalse(map2.getIfAbsentPut(0, true));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, false, 1, false), map2);
Assert.assertEquals(this.newWithKeysValues(0, false, 1, false), map2);

ObjectBooleanHashMap<Integer> map3 = ObjectBooleanHashMap.newMap();
MutableObjectBooleanMap<Integer> map3 = this.getEmptyMap();
Assert.assertTrue(map3.getIfAbsentPut(null, true));
Assert.assertTrue(map3.getIfAbsentPut(null, false));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(null, true), map3);
Assert.assertEquals(this.newWithKeysValues(null, true), map3);
}

@Test
public void updateValue()
{
BooleanToBooleanFunction flip = value -> !value;

ObjectBooleanHashMap<Integer> map1 = ObjectBooleanHashMap.newMap();
MutableObjectBooleanMap<Integer> map1 = this.getEmptyMap();
Assert.assertTrue(map1.updateValue(0, false, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, true), map1);
Assert.assertEquals(this.newWithKeysValues(0, true), map1);
Assert.assertFalse(map1.updateValue(0, false, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, false), map1);
Assert.assertEquals(this.newWithKeysValues(0, false), map1);
Assert.assertFalse(map1.updateValue(1, true, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, false, 1, false), map1);
Assert.assertEquals(this.newWithKeysValues(0, false, 1, false), map1);
Assert.assertTrue(map1.updateValue(1, true, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, false, 1, true), map1);
Assert.assertEquals(this.newWithKeysValues(0, false, 1, true), map1);

ObjectBooleanHashMap<Integer> map2 = ObjectBooleanHashMap.newMap();
MutableObjectBooleanMap<Integer> map2 = this.getEmptyMap();
Assert.assertTrue(map2.updateValue(1, false, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(1, true), map2);
Assert.assertEquals(this.newWithKeysValues(1, true), map2);
Assert.assertFalse(map2.updateValue(1, false, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(1, false), map2);
Assert.assertEquals(this.newWithKeysValues(1, false), map2);
Assert.assertFalse(map2.updateValue(0, true, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, false, 1, false), map2);
Assert.assertEquals(this.newWithKeysValues(0, false, 1, false), map2);
Assert.assertTrue(map2.updateValue(0, true, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(0, true, 1, false), map2);
Assert.assertEquals(this.newWithKeysValues(0, true, 1, false), map2);

ObjectBooleanHashMap<Integer> map3 = ObjectBooleanHashMap.newMap();
MutableObjectBooleanMap<Integer> map3 = this.getEmptyMap();
Assert.assertFalse(map3.updateValue(null, true, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(null, false), map3);
Assert.assertEquals(this.newWithKeysValues(null, false), map3);
Assert.assertTrue(map3.updateValue(null, true, flip));
Assert.assertEquals(ObjectBooleanHashMap.newWithKeysValues(null, true), map3);
Assert.assertEquals(this.newWithKeysValues(null, true), map3);
}

@Override
Expand Down

0 comments on commit dacbcf8

Please sign in to comment.