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

Function TestPriorityQueueUpdateOutOfBounds

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

Source from the content-addressed store, hash-verified

896}
897
898func TestPriorityQueueUpdateOutOfBounds(t *testing.T) {
899 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
900 pq, err := OpenPriorityQueue(file, ASC)
901 if err != nil {
902 t.Error(err)
903 }
904 defer pq.Drop()
905
906 for p := 0; p <= 4; p++ {
907 for i := 1; i <= 10; i++ {
908 if _, err = pq.EnqueueString(uint8(p), fmt.Sprintf("value for item %d", i)); err != nil {
909 t.Error(err)
910 }
911 }
912 }
913
914 if pq.Length() != 50 {
915 t.Errorf("Expected queue length of 50, got %d", pq.Length())
916 }
917
918 deqItem, err := pq.DequeueByPriority(3)
919 if err != nil {
920 t.Error(err)
921 }
922
923 if pq.Length() != 49 {
924 t.Errorf("Expected queue length of 49, got %d", pq.Length())
925 }
926
927 if _, err = pq.Update(deqItem.Priority, deqItem.ID, []byte(`new value`)); err != ErrOutOfBounds {
928 t.Errorf("Expected to get queue out of bounds error, got %s", err.Error())
929 }
930
931 if _, err = pq.Update(deqItem.Priority, deqItem.ID+1, []byte(`new value`)); err != nil {
932 t.Error(err)
933 }
934}
935
936func TestPriorityQueueHigherPriorityAsc(t *testing.T) {
937 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())

Callers

nothing calls this directly

Calls 6

OpenPriorityQueueFunction · 0.85
DequeueByPriorityMethod · 0.80
DropMethod · 0.45
EnqueueStringMethod · 0.45
LengthMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected