(t *testing.T)
| 613 | } |
| 614 | |
| 615 | func TestPriorityQueueUpdate(t *testing.T) { |
| 616 | file := fmt.Sprintf("test_db_%d", time.Now().UnixNano()) |
| 617 | pq, err := OpenPriorityQueue(file, ASC) |
| 618 | if err != nil { |
| 619 | t.Error(err) |
| 620 | } |
| 621 | defer pq.Drop() |
| 622 | |
| 623 | for p := 0; p <= 4; p++ { |
| 624 | for i := 1; i <= 10; i++ { |
| 625 | if _, err = pq.EnqueueString(uint8(p), fmt.Sprintf("value for item %d", i)); err != nil { |
| 626 | t.Error(err) |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | item, err := pq.PeekByPriorityID(0, 3) |
| 632 | if err != nil { |
| 633 | t.Error(err) |
| 634 | } |
| 635 | |
| 636 | oldCompStr := "value for item 3" |
| 637 | newCompStr := "new value for item 3" |
| 638 | |
| 639 | if item.ToString() != oldCompStr { |
| 640 | t.Errorf("Expected string to be '%s', got '%s'", oldCompStr, item.ToString()) |
| 641 | } |
| 642 | |
| 643 | updatedItem, err := pq.Update(item.Priority, item.ID, []byte(newCompStr)) |
| 644 | if err != nil { |
| 645 | t.Error(err) |
| 646 | } |
| 647 | |
| 648 | if updatedItem.Priority != 0 { |
| 649 | t.Errorf("Expected priority level to be 0, got %d", item.Priority) |
| 650 | } |
| 651 | |
| 652 | if updatedItem.ToString() != newCompStr { |
| 653 | t.Errorf("Expected current item value to be '%s', got '%s'", newCompStr, item.ToString()) |
| 654 | } |
| 655 | |
| 656 | newItem, err := pq.PeekByPriorityID(0, 3) |
| 657 | if err != nil { |
| 658 | t.Error(err) |
| 659 | } |
| 660 | |
| 661 | if newItem.Priority != 0 { |
| 662 | t.Errorf("Expected priority level to be 0, got %d", newItem.Priority) |
| 663 | } |
| 664 | |
| 665 | if newItem.ToString() != newCompStr { |
| 666 | t.Errorf("Expected new item value to be '%s', got '%s'", newCompStr, item.ToString()) |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | func TestPriorityQueueUpdateString(t *testing.T) { |
| 671 | file := fmt.Sprintf("test_db_%d", time.Now().UnixNano()) |
nothing calls this directly
no test coverage detected