@Test public void removeKey() { MutableObjectBooleanMap<String> map0 = this.newWithKeysValues("0", true, "1", false); map0.removeKey("1"); Assert.assertEquals(this.newWithKeysValues("0", true), map0); map0.removeKey("0"); Assert.assertEquals(ObjectBooleanHashMap.newMap(), map0); MutableObjectBooleanMap<String> map1 = this.newWithKeysValues("0", false, "1", true); map1.removeKey("0"); Assert.assertEquals(this.newWithKeysValues("1", true), map1); map1.removeKey("1"); Assert.assertEquals(ObjectBooleanHashMap.newMap(), map1); this.map.removeKey("5"); Assert.assertEquals(this.newWithKeysValues("0", true, "1", true, "2", false), this.map); this.map.removeKey("0"); Assert.assertEquals(this.newWithKeysValues("1", true, "2", false), this.map); this.map.removeKey("1"); Assert.assertEquals(this.newWithKeysValues("2", false), this.map); this.map.removeKey("2"); Assert.assertEquals(ObjectBooleanHashMap.newMap(), this.map); this.map.removeKey("0"); this.map.removeKey("1"); this.map.removeKey("2"); Assert.assertEquals(ObjectBooleanHashMap.newMap(), this.map); Verify.assertEmpty(this.map); this.map.put(null, true); Assert.assertTrue(this.map.get(null)); this.map.removeKey(null); Assert.assertFalse(this.map.get(null)); }
@Override protected MutableBooleanCollection newWith(boolean... elements) { ObjectBooleanHashMap<Integer> map = new ObjectBooleanHashMap<>(); for (int i = 0; i < elements.length; i++) { map.put(i, elements[i]); } return map.values(); }
protected static MutableList<String> generateCollisions() { MutableList<String> collisions = FastList.newList(); ObjectBooleanHashMap<String> hashMap = new ObjectBooleanHashMap<String>(); for (int each = 3; collisions.size() <= 10; each++) { if (hashMap.index(String.valueOf(each)) == hashMap.index(String.valueOf(3))) { collisions.add(String.valueOf(each)); } } return collisions; }
@Override @Test public void remove() { ObjectBooleanHashMap<Integer> map = ObjectBooleanHashMap.newWithKeysValues(1, true, 2, false, 3, true); MutableBooleanCollection collection = map.values(); Assert.assertTrue(collection.remove(false)); Assert.assertFalse(collection.contains(false)); Assert.assertTrue(collection.contains(true)); Assert.assertFalse(map.contains(false)); Assert.assertTrue(map.contains(true)); }
@Test public void withoutKey() { MutableObjectBooleanMap<Integer> hashMap = this.newWithKeysValues(1, true, 2, true, 3, false, 4, false); MutableObjectBooleanMap<Integer> actual = hashMap.withoutKey(5); Assert.assertSame(hashMap, actual); Assert.assertEquals(this.newWithKeysValues(1, true, 2, true, 3, false, 4, false), actual); Assert.assertEquals(this.newWithKeysValues(1, true, 2, true, 3, false), hashMap.withoutKey(4)); Assert.assertEquals(this.newWithKeysValues(1, true, 2, true), hashMap.withoutKey(3)); Assert.assertEquals(this.newWithKeysValues(1, true), hashMap.withoutKey(2)); Assert.assertEquals(ObjectBooleanHashMap.newMap(), hashMap.withoutKey(1)); Assert.assertEquals(ObjectBooleanHashMap.newMap(), hashMap.withoutKey(1)); }
@Test public void clear() { MutableObjectBooleanMap<String> hashMap = this.getEmptyMap(); hashMap.put("0", true); hashMap.clear(); Assert.assertEquals(ObjectBooleanHashMap.newMap(), hashMap); hashMap.put("1", false); hashMap.clear(); Assert.assertEquals(ObjectBooleanHashMap.newMap(), hashMap); hashMap.put(null, true); hashMap.clear(); Assert.assertEquals(ObjectBooleanHashMap.newMap(), hashMap); }
@Override @Test public void clear() { MutableBooleanCollection emptyCollection = this.newWith(); emptyCollection.clear(); Verify.assertSize(0, emptyCollection); ObjectBooleanHashMap<Integer> map = ObjectBooleanHashMap.newWithKeysValues(1, true, 2, false, 3, true); MutableBooleanCollection collection = map.values(); collection.clear(); Verify.assertEmpty(collection); Verify.assertEmpty(map); Verify.assertSize(0, collection); Assert.assertFalse(collection.contains(true)); Assert.assertFalse(collection.contains(false)); }
@Test public void put() { this.map.put("0", false); this.map.put("1", false); this.map.put("2", true); ObjectBooleanHashMap<String> expected = ObjectBooleanHashMap.newWithKeysValues("0", false, "1", false, "2", true); Assert.assertEquals(expected, this.map); this.map.put("5", true); expected.put("5", true); Assert.assertEquals(expected, this.map); this.map.put(null, false); expected.put(null, false); Assert.assertEquals(expected, this.map); }
@Test public void withoutAllKeys() { MutableObjectBooleanMap<Integer> hashMap = this.newWithKeysValues(1, true, 2, true, 3, false, 4, false); MutableObjectBooleanMap<Integer> actual = hashMap.withoutAllKeys(FastList.newListWith(5, 6, 7)); Assert.assertSame(hashMap, actual); Assert.assertEquals(this.newWithKeysValues(1, true, 2, true, 3, false, 4, false), actual); Assert.assertEquals( this.newWithKeysValues(1, true, 2, true), hashMap.withoutAllKeys(FastList.newListWith(5, 4, 3))); Assert.assertEquals( this.newWithKeysValues(1, true), hashMap.withoutAllKeys(FastList.newListWith(2))); Assert.assertEquals( ObjectBooleanHashMap.newMap(), hashMap.withoutAllKeys(FastList.newListWith(1))); Assert.assertEquals( ObjectBooleanHashMap.newMap(), hashMap.withoutAllKeys(FastList.newListWith(5, 6))); }
@Override protected <T> UnmodifiableObjectBooleanMap<T> newWithKeysValues( T key1, boolean value1, T key2, boolean value2, T key3, boolean value3, T key4, boolean value4) { return new UnmodifiableObjectBooleanMap<T>( ObjectBooleanHashMap.newWithKeysValues( key1, value1, key2, value2, key3, value3, key4, value4)); }
@Test public void select() { Assert.assertEquals( BooleanHashBag.newBagWith(true, true), this.map.select(BooleanPredicates.isTrue()).toBag()); Assert.assertEquals( BooleanHashBag.newBagWith(false), this.map.select(BooleanPredicates.isFalse()).toBag()); Assert.assertEquals( BooleanHashBag.newBagWith(true, true, false), this.map .select(BooleanPredicates.or(BooleanPredicates.isTrue(), BooleanPredicates.isFalse())) .toBag()); Assert.assertEquals( new BooleanHashBag(), this.map .select(BooleanPredicates.and(BooleanPredicates.isTrue(), BooleanPredicates.isFalse())) .toBag()); Assert.assertEquals( this.newWithKeysValues("0", true), this.map.select( new ObjectBooleanPredicate<String>() { public boolean accept(String object, boolean value) { return (Integer.parseInt(object) & 1) == 0 && value; } })); Assert.assertEquals( this.newWithKeysValues("2", false), this.map.select( new ObjectBooleanPredicate<String>() { public boolean accept(String object, boolean value) { return (Integer.parseInt(object) & 1) == 0 && !value; } })); Assert.assertEquals( ObjectBooleanHashMap.newMap(), this.map.select( new ObjectBooleanPredicate<String>() { public boolean accept(String object, boolean value) { return (Integer.parseInt(object) & 1) != 0 && !value; } })); }
@Override @Test public void removeAll() { Assert.assertFalse(this.newWith().removeAll()); ObjectBooleanHashMap<Integer> map = ObjectBooleanHashMap.newWithKeysValues(1, true, null, false); MutableBooleanCollection collection = map.values(); Assert.assertFalse(collection.removeAll()); Assert.assertTrue(collection.removeAll(false)); Assert.assertFalse(collection.contains(false)); Assert.assertTrue(collection.contains(true)); Assert.assertFalse(map.contains(false)); Assert.assertTrue(map.contains(true)); Assert.assertTrue(collection.removeAll(true)); Assert.assertTrue(collection.isEmpty()); Assert.assertFalse(collection.contains(true)); Assert.assertFalse(collection.contains(false)); Assert.assertFalse(map.contains(true)); Assert.assertFalse(map.contains(false)); Assert.assertTrue(map.isEmpty()); }
@Override public <K> MutableObjectBooleanMap<K> newWithKeysValues(K key1, boolean value1) { return ObjectBooleanHashMap.newWithKeysValues(key1, value1).asUnmodifiable(); }
@Override protected MutableBooleanCollection classUnderTest() { return ObjectBooleanHashMap.newWithKeysValues(1, true, 2, false, 3, true).values(); }
@Override protected UnmodifiableObjectBooleanMap<String> classUnderTest() { return new UnmodifiableObjectBooleanMap<String>( ObjectBooleanHashMap.newWithKeysValues("0", true, "1", true, "2", false)); }
@Override protected <T> UnmodifiableObjectBooleanMap<T> newWithKeysValues(T key1, boolean value1) { return new UnmodifiableObjectBooleanMap<T>( ObjectBooleanHashMap.newWithKeysValues(key1, value1)); }
@Override public MutableObjectBooleanMap<Object> newEmpty() { return ObjectBooleanHashMap.newMap().asUnmodifiable(); }