MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / TestZSetNodes_InsertNode

Function TestZSetNodes_InsertNode

structure/zset_test.go:749–781  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

747 }
748}
749func TestZSetNodes_InsertNode(t *testing.T) {
750 pq := &FZSet{}
751
752 // Case 1: Insert new node
753 err := pq.InsertNode(1, "test", "value")
754 if err != nil {
755 t.Error("Failed when inserting a new node")
756 }
757
758 if _, ok := pq.dict["test"]; !ok {
759 t.Error("Insert node failed, expected key to exist in dictionary")
760 }
761
762 // Case 2: Update existing node with same score
763 err = pq.InsertNode(1, "test", "newvalue")
764 if err != nil {
765 t.Error("Failed when updating a score with same value")
766 }
767
768 if v, ok := pq.dict["test"]; !ok || v.value != "newvalue" {
769 t.Error("Update node failed, expected value to be updated")
770 }
771
772 // Case 3: Insert node with existing key but different score
773 err = pq.InsertNode(2, "test", "newvalue")
774 if err != nil {
775 t.Error("Failed when updating a score with a new value")
776 }
777
778 if v, ok := pq.dict["test"]; !ok || v.score != 2 {
779 t.Error("Update node failed, expected score to be updated")
780 }
781}
782func TestZCount(t *testing.T) {
783 zs, _ := initZSetDB()
784

Callers

nothing calls this directly

Calls 1

InsertNodeMethod · 0.95

Tested by

no test coverage detected