| 20 | ) |
| 21 | |
| 22 | func TestPQueue(t *testing.T) { |
| 23 | pq := utils.PQueue{} |
| 24 | |
| 25 | heap.Init(&pq) |
| 26 | heap.Push(&pq, utils.PQueueNode{Priority: 4, Data: "4"}) |
| 27 | heap.Push(&pq, utils.PQueueNode{Priority: 0, Data: "0"}) |
| 28 | heap.Push(&pq, utils.PQueueNode{Priority: 2, Data: "2"}) |
| 29 | |
| 30 | if heap.Pop(&pq).(utils.PQueueNode).Data.(string) != "0" { |
| 31 | t.Errorf("") |
| 32 | } |
| 33 | |
| 34 | heap.Push(&pq, utils.PQueueNode{Priority: 1, Data: "1"}) |
| 35 | |
| 36 | if heap.Pop(&pq).(utils.PQueueNode).Data.(string) != "1" { |
| 37 | t.Errorf("") |
| 38 | } |
| 39 | |
| 40 | if heap.Pop(&pq).(utils.PQueueNode).Data.(string) != "2" { |
| 41 | t.Errorf("") |
| 42 | } |
| 43 | |
| 44 | if heap.Pop(&pq).(utils.PQueueNode).Data.(string) != "4" { |
| 45 | t.Errorf("") |
| 46 | } |
| 47 | |
| 48 | if pq.Len() != 0 { |
| 49 | t.Errorf("") |
| 50 | } |
| 51 | |
| 52 | } |