From f5f7691de09f11f690030fe3c7267e5144edf003 Mon Sep 17 00:00:00 2001 From: ajet Date: Tue, 4 Nov 2025 17:17:00 -1000 Subject: [PATCH] try PBT with coverage #2 --- list/list_test.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/list/list_test.go b/list/list_test.go index 017fdae..a2b824a 100644 --- a/list/list_test.go +++ b/list/list_test.go @@ -6,6 +6,8 @@ import ( "testing" ) +/* + func TestListLen(t *testing.T) { assert.Equal(t, 0, Empty().Len(), "should insert at head") assert.Equal(t, 1, Empty().Conj(1).Len(), "should insert at head") @@ -39,26 +41,33 @@ func TestListRest(t *testing.T) { assert.Equal(t, Empty(), Empty().Rest(), "should return rest sublist") assert.Equal(t, Empty(), Empty().Rest().Rest(), "should return rest sublist") } +*/ -// generative tests -func ListLengthProperty(t *testing.T) { - myList := Empty() - expectedSized := 0 - rapid.Check(t, func(t *rapid.T) { +func intListGen() *rapid.Generator[IList] { + return rapid.Custom(func(t *rapid.T) IList { + myList := Empty() t.Repeat(map[string]func(*rapid.T){ "conj": func(t *rapid.T) { - expectedSized += 1 myList = myList.Conj(rapid.Int().Draw(t, "el")) }, - "rest": func(t *rapid.T) { - if !myList.IsEmpty() { - expectedSized -= 1 - } - myList = myList.Rest() - }, - "": func(t *rapid.T) { - assert.Equal(t, myList.Len(), expectedSized, "must be equal") - }, }) + return myList + }) +} + +// generative tests +func TestConjIncreasesLength(t *testing.T) { + rapid.Check(t, func(t *rapid.T) { + myList := intListGen().Draw(t, "myList") + assert.Equal(t, myList.Len()+1, myList.Conj(42).Len()) + }) +} + +func TestRestDecreasesLengthForNonEmptyList(t *testing.T) { + rapid.Check(t, func(t *rapid.T) { + myList := intListGen().Filter(func(l IList) bool { + return !l.IsEmpty() + }).Draw(t, "myList") + assert.Equal(t, myList.Len()-1, myList.Rest().Len()) }) }