never go full pbt ;)
All checks were successful
Go / test (push) Successful in 3s

This commit is contained in:
Adam Jeniski 2025-11-04 17:36:18 -10:00
parent 8dd6fd958d
commit 6155074b77

View File

@ -1,48 +1,14 @@
package list package list
import ( import (
"regexp"
"strings"
"testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"pgregory.net/rapid" "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] { func intListGen() *rapid.Generator[IList] {
return rapid.OneOf(rapid.Custom(func(t *rapid.T) IList { return rapid.OneOf(rapid.Custom(func(t *rapid.T) IList {
myList := Empty() myList := Empty()
@ -78,3 +44,18 @@ func TestFirstIsNilWhenEmpty(t *testing.T) {
assert.Equal(t, myList.IsEmpty(), myList.First() == nil) 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, " "))
}
})
}