From 6155074b776a3f8e1e8856cba0214ccfb64d7266 Mon Sep 17 00:00:00 2001 From: ajet Date: Tue, 4 Nov 2025 17:36:18 -1000 Subject: [PATCH] never go full pbt ;) --- list/list_test.go | 57 ++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/list/list_test.go b/list/list_test.go index 9386cb0..80e7ee1 100644 --- a/list/list_test.go +++ b/list/list_test.go @@ -1,48 +1,14 @@ package list import ( + "regexp" + "strings" + "testing" + "github.com/stretchr/testify/assert" "pgregory.net/rapid" - "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") - assert.Equal(t, 2, Empty().Conj(1).Conj(2).Len(), "should insert at head") -} - -func TestListString(t *testing.T) { - assert.Equal(t, "()", Empty().String(), "should insert at head") -} - -func TestListConj(t *testing.T) { - var l IList - assert.Equal(t, "()", Empty().String(), "should insert at head") - l = New(5) - assert.Equal(t, "(5)", l.String(), "should insert at head") - l = Empty().Conj(4) - assert.Equal(t, "(4)", l.String(), "should insert at head") -} - -func TestListFirst(t *testing.T) { - l := Empty().Conj(5).Conj(6).Conj(7) - assert.Equal(t, 7, l.First(), "should return first element") - assert.Equal(t, nil, Empty().First(), "should return nil") -} - -func TestListRest(t *testing.T) { - l := Empty().Conj(5).Conj(6).Conj(7) - assert.Equal(t, "(6 5)", l.Rest().String(), "should return rest sublist") - assert.Equal(t, "(5)", l.Rest().Rest().String(), "should return rest sublist") - assert.Equal(t, "()", l.Rest().Rest().Rest().String(), "should return rest sublist") - assert.Equal(t, Empty(), Empty().Rest(), "should return rest sublist") - assert.Equal(t, Empty(), Empty().Rest().Rest(), "should return rest sublist") -} -*/ - func intListGen() *rapid.Generator[IList] { return rapid.OneOf(rapid.Custom(func(t *rapid.T) IList { myList := Empty() @@ -78,3 +44,18 @@ func TestFirstIsNilWhenEmpty(t *testing.T) { assert.Equal(t, myList.IsEmpty(), myList.First() == nil) }) } + +func TestStringifyIntList(t *testing.T) { + assert.Equal(t, "(1 2 3)", New(3).Conj(2).Conj(1).String()) + rapid.Check(t, func(t *rapid.T) { + myList := intListGen().Draw(t, "myList") + s := myList.String() + r := regexp.MustCompile(`\(.*\)`) + assert.Equal(t, true, r.Match([]byte(s))) + if !myList.IsEmpty() { + assert.Equal(t, myList.Len(), strings.Count(s, " ")+1) + } else { + assert.Equal(t, 0, strings.Count(s, " ")) + } + }) +}