@@ -36,23 +36,36 @@ func TestLargeVectorConsCoallocatesResultAndTail(t *testing.T) {
3636}
3737
3838func TestVectorReplaceLastIsPersistentAndCoallocated (t * testing.T ) {
39- original := NewVector ()
40- for _ , value := range []int {1 , 2 , 3 , 4 , 5 } {
41- original = original .Cons (value ).(* Vector )
42- }
43- var result * Vector
44- if got := testing .AllocsPerRun (1_000 , func () {
45- result = original .ReplaceLast (9 )
46- }); got != 1 {
47- t .Fatalf ("replace-last allocated %v objects per call, want 1" , got )
48- }
49- if got := original .Nth (4 ); got != 5 {
50- t .Fatalf ("original final value = %v, want 5" , got )
51- }
52- if got := result .Nth (4 ); got != 9 {
53- t .Fatalf ("replacement final value = %v, want 9" , got )
39+ tests := []struct {
40+ name string
41+ original * Vector
42+ }{
43+ {"base tail" , NewVector (1 , 2 , 3 , 4 , 5 )},
44+ {"delta tail" , func () * Vector {
45+ vector := NewVector ()
46+ for _ , value := range []int {1 , 2 , 3 , 4 , 5 } {
47+ vector = vector .Cons (value ).(* Vector )
48+ }
49+ return vector
50+ }()},
51+ }
52+ for _ , test := range tests {
53+ t .Run (test .name , func (t * testing.T ) {
54+ var result * Vector
55+ if got := testing .AllocsPerRun (1_000 , func () {
56+ result = test .original .ReplaceLast (9 )
57+ }); got != 1 {
58+ t .Fatalf ("replace-last allocated %v objects per call, want 1" , got )
59+ }
60+ if got := test .original .Nth (4 ); got != 5 {
61+ t .Fatalf ("original final value = %v, want 5" , got )
62+ }
63+ if got := result .Nth (4 ); got != 9 {
64+ t .Fatalf ("replacement final value = %v, want 9" , got )
65+ }
66+ runtime .KeepAlive (result )
67+ })
5468 }
55- runtime .KeepAlive (result )
5669}
5770
5871func TestSmallVectorWithMetaKeepsInlineStorageAlive (t * testing.T ) {
0 commit comments