MCPcopy Create free account
hub / github.com/benbjohnson/immutable / TestInternal_mapValueNode

Function TestInternal_mapValueNode

immutable_test.go:772–947  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

770}
771
772func TestInternal_mapValueNode(t *testing.T) {
773 t.Run("Simple", func(t *testing.T) {
774 var h defaultHasher[int]
775 n := newMapValueNode(h.Hash(2), 2, 3)
776 if v, ok := n.get(2, 0, h.Hash(2), &h); !ok {
777 t.Fatal("expected ok")
778 } else if v != 3 {
779 t.Fatalf("unexpected value: %v", v)
780 }
781 })
782
783 t.Run("KeyEqual", func(t *testing.T) {
784 var h defaultHasher[int]
785 var resized bool
786 n := newMapValueNode(h.Hash(2), 2, 3)
787 other := n.set(2, 4, 0, h.Hash(2), &h, false, &resized).(*mapValueNode[int, int])
788 if other == n {
789 t.Fatal("expected new node")
790 } else if got, exp := other.keyHash, h.Hash(2); got != exp {
791 t.Fatalf("keyHash=%v, expected %v", got, exp)
792 } else if got, exp := other.key, 2; got != exp {
793 t.Fatalf("key=%v, expected %v", got, exp)
794 } else if got, exp := other.value, 4; got != exp {
795 t.Fatalf("value=%v, expected %v", got, exp)
796 } else if resized {
797 t.Fatal("unexpected resize")
798 }
799 })
800
801 t.Run("KeyHashEqual", func(t *testing.T) {
802 h := &mockHasher[int]{
803 hash: func(value int) uint32 { return 1 },
804 equal: func(a, b int) bool { return a == b },
805 }
806 var resized bool
807 n := newMapValueNode(h.Hash(2), 2, 3)
808 other := n.set(4, 5, 0, h.Hash(4), h, false, &resized).(*mapHashCollisionNode[int, int])
809 if got, exp := other.keyHash, h.Hash(2); got != exp {
810 t.Fatalf("keyHash=%v, expected %v", got, exp)
811 } else if got, exp := len(other.entries), 2; got != exp {
812 t.Fatalf("entries=%v, expected %v", got, exp)
813 } else if !resized {
814 t.Fatal("expected resize")
815 }
816 if got, exp := other.entries[0].key, 2; got != exp {
817 t.Fatalf("key[0]=%v, expected %v", got, exp)
818 } else if got, exp := other.entries[0].value, 3; got != exp {
819 t.Fatalf("value[0]=%v, expected %v", got, exp)
820 }
821 if got, exp := other.entries[1].key, 4; got != exp {
822 t.Fatalf("key[1]=%v, expected %v", got, exp)
823 } else if got, exp := other.entries[1].value, 5; got != exp {
824 t.Fatalf("value[1]=%v, expected %v", got, exp)
825 }
826 })
827
828 t.Run("MergeNode", func(t *testing.T) {
829 // Inserting into a node with a different index in the mask should split into a bitmap node.

Callers

nothing calls this directly

Calls 4

newMapValueNodeFunction · 0.85
HashMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…