TestHeap_ListKeys tests Heap.ListKeys function. Scenario is the same as TestHeap_list.
(t *testing.T)
| 337 | // TestHeap_ListKeys tests Heap.ListKeys function. Scenario is the same as |
| 338 | // TestHeap_list. |
| 339 | func TestHeap_ListKeys(t *testing.T) { |
| 340 | h := NewHeap(testHeapObjectKeyFunc, compareInts) |
| 341 | list := h.ListKeys() |
| 342 | if len(list) != 0 { |
| 343 | t.Errorf("expected an empty list") |
| 344 | } |
| 345 | |
| 346 | items := map[string]int{ |
| 347 | "foo": 10, |
| 348 | "bar": 1, |
| 349 | "bal": 30, |
| 350 | "baz": 11, |
| 351 | "faz": 30, |
| 352 | } |
| 353 | for k, v := range items { |
| 354 | h.Add(mkHeapObj(k, v)) |
| 355 | } |
| 356 | list = h.ListKeys() |
| 357 | if len(list) != len(items) { |
| 358 | t.Errorf("expected %d items, got %d", len(items), len(list)) |
| 359 | } |
| 360 | for _, key := range list { |
| 361 | _, ok := items[key] |
| 362 | if !ok { |
| 363 | t.Errorf("unexpected item in the list: %v", key) |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | // TestHeapAddAfterClose tests that heap returns an error if anything is added |
| 369 | // after it is closed. |