(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestHashMap(t *testing.T) { |
| 10 | mp := hashmap.DefaultNew() |
| 11 | |
| 12 | t.Run("Test 1: Put(10) and checking if Get() is correct", func(t *testing.T) { |
| 13 | mp.Put("test", 10) |
| 14 | got := mp.Get("test") |
| 15 | if got != 10 { |
| 16 | t.Errorf("Put: %v, Got: %v", 10, got) |
| 17 | } |
| 18 | }) |
| 19 | |
| 20 | t.Run("Test 2: Reassiging the value and checking if its correct", func(t *testing.T) { |
| 21 | mp.Put("test", 20) |
| 22 | got := mp.Get("test") |
| 23 | if got != 20 { |
| 24 | t.Errorf("Put (reassign): %v, Got: %v", 20, got) |
| 25 | } |
| 26 | }) |
| 27 | |
| 28 | t.Run("Test 3: Adding new key when there is already some data", func(t *testing.T) { |
| 29 | mp.Put("test2", 30) |
| 30 | got := mp.Get("test2") |
| 31 | if got != 30 { |
| 32 | t.Errorf("Put: %v, Got: %v", got, 30) |
| 33 | } |
| 34 | }) |
| 35 | |
| 36 | t.Run("Test 4: Adding numeric key", func(t *testing.T) { |
| 37 | mp.Put(1, 40) |
| 38 | got := mp.Get(1) |
| 39 | if got != 40 { |
| 40 | t.Errorf("Put: %v, Got: %v", got, 40) |
| 41 | } |
| 42 | }) |
| 43 | |
| 44 | t.Run("Test 5: Checking the Contains function", func(t *testing.T) { |
| 45 | want := true |
| 46 | got := mp.Contains(1) |
| 47 | if want != got { |
| 48 | t.Errorf("Key '1' exists but couldn't be retrieved") |
| 49 | } |
| 50 | }) |
| 51 | |
| 52 | t.Run("Test 6: Checking if the key that does not exist returns false", func(t *testing.T) { |
| 53 | want := false |
| 54 | got := mp.Contains(2) |
| 55 | if got != want { |
| 56 | t.Errorf("Key '2' does not exist in the map but it says otherwise") |
| 57 | } |
| 58 | }) |
| 59 | |
| 60 | t.Run("Test 7: Checking if the key does not exist Get func returns nil", func(t *testing.T) { |
| 61 | want := any(nil) |
| 62 | got := mp.Get(2) |
| 63 | if got != want { |
| 64 | t.Errorf("Key '2' does not exists in the map but it says otherwise") |
| 65 | } |
| 66 | }) |
nothing calls this directly
no test coverage detected