fn: add transpositions for Option and Result
This commit is contained in:
4 files changed
+74
No files matched your search
@@ -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))
|
||||
}
|
||||
Reference in new issue
Block a user