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

Function TestInternal_mapArrayNode

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

Source from the content-addressed store, hash-verified

693}
694
695func TestInternal_mapArrayNode(t *testing.T) {
696 // Ensure 8 or fewer elements stays in an array node.
697 t.Run("Append", func(t *testing.T) {
698 var h defaultHasher[int]
699 n := &mapArrayNode[int, int]{}
700 for i := 0; i < 8; i++ {
701 var resized bool
702 n = n.set(i*10, i, 0, h.Hash(i*10), &h, false, &resized).(*mapArrayNode[int, int])
703 if !resized {
704 t.Fatal("expected resize")
705 }
706
707 for j := 0; j < i; j++ {
708 if v, ok := n.get(j*10, 0, h.Hash(j*10), &h); !ok || v != j {
709 t.Fatalf("get(%d)=<%v,%v>", j, v, ok)
710 }
711 }
712 }
713 })
714
715 // Ensure 8 or fewer elements stays in an array node when inserted in reverse.
716 t.Run("Prepend", func(t *testing.T) {
717 var h defaultHasher[int]
718 n := &mapArrayNode[int, int]{}
719 for i := 7; i >= 0; i-- {
720 var resized bool
721 n = n.set(i*10, i, 0, h.Hash(i*10), &h, false, &resized).(*mapArrayNode[int, int])
722 if !resized {
723 t.Fatal("expected resize")
724 }
725
726 for j := i; j <= 7; j++ {
727 if v, ok := n.get(j*10, 0, h.Hash(j*10), &h); !ok || v != j {
728 t.Fatalf("get(%d)=<%v,%v>", j, v, ok)
729 }
730 }
731 }
732 })
733
734 // Ensure array can transition between node types.
735 t.Run("Expand", func(t *testing.T) {
736 var h defaultHasher[int]
737 var n mapNode[int, int] = &mapArrayNode[int, int]{}
738 for i := 0; i < 100; i++ {
739 var resized bool
740 n = n.set(i, i, 0, h.Hash(i), &h, false, &resized)
741 if !resized {
742 t.Fatal("expected resize")
743 }
744
745 for j := 0; j < i; j++ {
746 if v, ok := n.get(j, 0, h.Hash(j), &h); !ok || v != j {
747 t.Fatalf("get(%d)=<%v,%v>", j, v, ok)
748 }
749 }
750 }
751 })
752

Callers

nothing calls this directly

Calls 5

RunRandomFunction · 0.85
setMethod · 0.65
HashMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…