Merge pull request #10434 from MeenaGawande/master
[BAEL-4715] Java HashMap Load Factor
This commit is contained in:
commit
82023cf57a
|
@ -0,0 +1,49 @@
|
|||
package com.baeldung.map.hashmap.loadfactor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class HashMapLoadFactorUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateMapWithDefaultParam_thenSucces() {
|
||||
Map<String, String> mapWithDefaultParams = new HashMap<>();
|
||||
mapWithDefaultParams.put("1", "one");
|
||||
mapWithDefaultParams.put("2", "two");
|
||||
mapWithDefaultParams.put("3", "three");
|
||||
mapWithDefaultParams.put("4", "four");
|
||||
mapWithDefaultParams.put("5", "five");
|
||||
|
||||
Assert.assertEquals(5, mapWithDefaultParams.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateMapWithInitialCapacity_thenSucces() {
|
||||
Map<String, String> mapWithInitialCapacity = new HashMap<>(5);
|
||||
mapWithInitialCapacity.put("1", "one");
|
||||
mapWithInitialCapacity.put("2", "two");
|
||||
mapWithInitialCapacity.put("3", "three");
|
||||
|
||||
Assert.assertEquals(3, mapWithInitialCapacity.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateMapWithInitialCapacityAndLF_thenSucces() {
|
||||
Map<String, String> mapWithInitialCapacityAndLF = new HashMap<>(5, 0.5f);
|
||||
mapWithInitialCapacityAndLF.put("1", "one");
|
||||
mapWithInitialCapacityAndLF.put("2", "two");
|
||||
mapWithInitialCapacityAndLF.put("3", "three");
|
||||
mapWithInitialCapacityAndLF.put("4", "four");
|
||||
mapWithInitialCapacityAndLF.put("5", "five");
|
||||
mapWithInitialCapacityAndLF.put("6", "six");
|
||||
mapWithInitialCapacityAndLF.put("7", "seven");
|
||||
mapWithInitialCapacityAndLF.put("8", "eight");
|
||||
mapWithInitialCapacityAndLF.put("9", "nine");
|
||||
mapWithInitialCapacityAndLF.put("10", "ten");
|
||||
|
||||
Assert.assertEquals(10, mapWithInitialCapacityAndLF.size());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue