try PBT with coverage #2
All checks were successful
Go / test (push) Successful in 3s

This commit is contained in:
Adam Jeniski 2025-11-04 17:17:00 -10:00
parent b9b88d8fa0
commit f5f7691de0

View File

@ -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) {
func intListGen() *rapid.Generator[IList] {
return rapid.Custom(func(t *rapid.T) IList {
myList := Empty()
expectedSized := 0
rapid.Check(t, func(t *rapid.T) {
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())
})
}