(t *testing.T)
| 668 | } |
| 669 | |
| 670 | func TestPriorityQueueUpdateString(t *testing.T) { |
| 671 | file := fmt.Sprintf("test_db_%d", time.Now().UnixNano()) |
| 672 | pq, err := OpenPriorityQueue(file, ASC) |
| 673 | if err != nil { |
| 674 | t.Error(err) |
| 675 | } |
| 676 | defer pq.Drop() |
| 677 | |
| 678 | for p := 0; p <= 4; p++ { |
| 679 | for i := 1; i <= 10; i++ { |
| 680 | if _, err = pq.EnqueueString(uint8(p), fmt.Sprintf("value for item %d", i)); err != nil { |
| 681 | t.Error(err) |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | item, err := pq.PeekByPriorityID(0, 3) |
| 687 | if err != nil { |
| 688 | t.Error(err) |
| 689 | } |
| 690 | |
| 691 | oldCompStr := "value for item 3" |
| 692 | newCompStr := "new value for item 3" |
| 693 | |
| 694 | if item.ToString() != oldCompStr { |
| 695 | t.Errorf("Expected string to be '%s', got '%s'", oldCompStr, item.ToString()) |
| 696 | } |
| 697 | |
| 698 | updatedItem, err := pq.UpdateString(item.Priority, item.ID, newCompStr) |
| 699 | if err != nil { |
| 700 | t.Error(err) |
| 701 | } |
| 702 | |
| 703 | if updatedItem.Priority != 0 { |
| 704 | t.Errorf("Expected priority level to be 0, got %d", item.Priority) |
| 705 | } |
| 706 | |
| 707 | if updatedItem.ToString() != newCompStr { |
| 708 | t.Errorf("Expected current item value to be '%s', got '%s'", newCompStr, item.ToString()) |
| 709 | } |
| 710 | |
| 711 | newItem, err := pq.PeekByPriorityID(0, 3) |
| 712 | if err != nil { |
| 713 | t.Error(err) |
| 714 | } |
| 715 | |
| 716 | if newItem.Priority != 0 { |
| 717 | t.Errorf("Expected priority level to be 0, got %d", newItem.Priority) |
| 718 | } |
| 719 | |
| 720 | if newItem.ToString() != newCompStr { |
| 721 | t.Errorf("Expected new item value to be '%s', got '%s'", newCompStr, item.ToString()) |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | func TestPriorityQueueUpdateObject(t *testing.T) { |
| 726 | file := fmt.Sprintf("test_db_%d", time.Now().UnixNano()) |
nothing calls this directly
no test coverage detected