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

Function TestInternal_mapNode_Overwrite

immutable_test.go:661–693  ·  view source on GitHub ↗

Ensure node can support overwrites as it expands.

(t *testing.T)

Source from the content-addressed store, hash-verified

659
660// Ensure node can support overwrites as it expands.
661func TestInternal_mapNode_Overwrite(t *testing.T) {
662 const n = 1000
663 var h defaultHasher[int]
664 var node mapNode[int, int] = &mapArrayNode[int, int]{}
665 for i := 0; i < n; i++ {
666 var resized bool
667 node = node.set(i, i, 0, h.Hash(i), &h, false, &resized)
668 if !resized {
669 t.Fatal("expected resize")
670 }
671
672 // Overwrite every node.
673 for j := 0; j <= i; j++ {
674 var resized bool
675 node = node.set(j, i*j, 0, h.Hash(j), &h, false, &resized)
676 if resized {
677 t.Fatalf("expected no resize: i=%d, j=%d", i, j)
678 }
679 }
680
681 // Verify not found at each branch type.
682 if _, ok := node.get(1000000, 0, h.Hash(1000000), &h); ok {
683 t.Fatal("expected no value")
684 }
685 }
686
687 // Verify all key/value pairs in map.
688 for i := 0; i < n; i++ {
689 if v, ok := node.get(i, 0, h.Hash(i), &h); !ok || v != i*(n-1) {
690 t.Fatalf("get(%d)=<%v,%v>", i, v, ok)
691 }
692 }
693}
694
695func TestInternal_mapArrayNode(t *testing.T) {
696 // Ensure 8 or fewer elements stays in an array node.

Callers

nothing calls this directly

Calls 3

setMethod · 0.65
HashMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…