MCPcopy Create free account
hub / github.com/beeker1121/goque / TestPriorityQueueUpdateObject

Function TestPriorityQueueUpdateObject

priority_queue_test.go:725–796  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

723}
724
725func TestPriorityQueueUpdateObject(t *testing.T) {
726 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
727 pq, err := OpenPriorityQueue(file, ASC)
728 if err != nil {
729 t.Error(err)
730 }
731 defer pq.Drop()
732
733 type object struct {
734 Priority uint8
735 Value int
736 }
737
738 for p := 0; p <= 4; p++ {
739 for i := 1; i <= 10; i++ {
740 if _, err = pq.EnqueueObject(uint8(p), object{uint8(p), i}); err != nil {
741 t.Error(err)
742 }
743 }
744 }
745
746 item, err := pq.PeekByPriorityID(0, 3)
747 if err != nil {
748 t.Error(err)
749 }
750
751 oldCompObj := object{0, 3}
752 newCompObj := object{0, 33}
753
754 var obj object
755 if err := item.ToObject(&obj); err != nil {
756 t.Error(err)
757 }
758
759 if obj != oldCompObj {
760 t.Errorf("Expected object to be '%+v', got '%+v'", oldCompObj, obj)
761 }
762
763 updatedItem, err := pq.UpdateObject(item.Priority, item.ID, newCompObj)
764 if err != nil {
765 t.Error(err)
766 }
767
768 if updatedItem.Priority != 0 {
769 t.Errorf("Expected priority level to be 0, got %d", item.Priority)
770 }
771
772 if err := updatedItem.ToObject(&obj); err != nil {
773 t.Error(err)
774 }
775
776 if obj != newCompObj {
777 t.Errorf("Expected current object to be '%+v', got '%+v'", newCompObj, obj)
778 }
779
780 newItem, err := pq.PeekByPriorityID(0, 3)
781 if err != nil {
782 t.Error(err)

Callers

nothing calls this directly

Calls 6

OpenPriorityQueueFunction · 0.85
PeekByPriorityIDMethod · 0.80
DropMethod · 0.45
EnqueueObjectMethod · 0.45
ToObjectMethod · 0.45
UpdateObjectMethod · 0.45

Tested by

no test coverage detected