fn: add transpositions for Option and Result

This commit is contained in:
Keagan McClelland committed 2024-11-06 16:40:36 -07:00
1 parent 8971c4c3ae
commit 5dec35426c
4 files changed
+74

No files matched your search

+25
View File
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"testing"
"testing/quick"
"github.com/stretchr/testify/require"
)
@@ -26,3 +27,27 @@ func TestSomeToOkf(t *testing.T) {
Err[uint8](fmt.Errorf(errStr)),
)
}
func TestPropTransposeOptResInverts(t *testing.T) {
f := func(i uint) bool {
var o Option[Result[uint]]
switch i % 3 {
case 0:
o = Some(Ok(i))
case 1:
o = Some(Errf[uint]("error"))
case 2:
o = None[Result[uint]]()
default:
return false
}
odd := TransposeOptRes(o) ==
TransposeOptRes(TransposeResOpt(TransposeOptRes(o)))
even := TransposeResOpt(TransposeOptRes(o)) == o
return odd && even
}
require.NoError(t, quick.Check(f, nil))
}