From bdfdabc970ef286de9390ff0ab7740ff1145d388 Mon Sep 17 00:00:00 2001 From: Oskar Haarklou Veileborg Date: Thu, 12 Jan 2023 10:59:36 +0100 Subject: list: fix Append & Prepend, remove varargs support Similar reason for the API change as the previous commit. --- immutable_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'immutable_test.go') diff --git a/immutable_test.go b/immutable_test.go index a878a78..9a0de37 100644 --- a/immutable_test.go +++ b/immutable_test.go @@ -223,6 +223,19 @@ func TestList(t *testing.T) { } }) + t.Run("AppendImmutable", func(t *testing.T) { + outer_l := NewList[int]() + for N := 0; N < 1_000; N++ { + l1 := outer_l.Append(0) + outer_l.Append(1) + if actual := l1.Get(N); actual != 0 { + t.Fatalf("Append mutates list with %d elements. Got %d instead of 0", N, actual) + } + + outer_l = outer_l.Append(0) + } + }) + RunRandom(t, "Random", func(t *testing.T, rand *rand.Rand) { l := NewTList() for i := 0; i < 100000; i++ { -- cgit v1.2.3 From bda5726650b18edea367db0fb16a29b9e711e3e2 Mon Sep 17 00:00:00 2001 From: Oskar Haarklou Veileborg Date: Thu, 12 Jan 2023 11:00:26 +0100 Subject: Fix random seed for TestRandom The closure passed to t.Run captured the loop variable which would always be equal to `*randomN` once the tests started running. This meant that all of the runs used the same random seed. --- immutable_test.go | 1 + 1 file changed, 1 insertion(+) (limited to 'immutable_test.go') diff --git a/immutable_test.go b/immutable_test.go index 9a0de37..581d4d8 100644 --- a/immutable_test.go +++ b/immutable_test.go @@ -2495,6 +2495,7 @@ func RunRandom(t *testing.T, name string, fn func(t *testing.T, rand *rand.Rand) } t.Run(name, func(t *testing.T) { for i := 0; i < *randomN; i++ { + i := i t.Run(fmt.Sprintf("%08d", i), func(t *testing.T) { t.Parallel() fn(t, rand.New(rand.NewSource(int64(i)))) -- cgit v1.2.3