go-nul/nullable_filter_test.go

62 lines
1.1 KiB
Go
Raw Normal View History

2023-09-23 22:59:33 +00:00
package nul_test
import (
"testing"
"github.com/reiver/go-nul"
2023-09-23 22:59:33 +00:00
)
2023-11-02 15:21:26 +00:00
func TestNullable_Filter_int(t *testing.T) {
2023-09-23 22:59:33 +00:00
tests := []struct{
Nullable nul.Nullable[int]
Expected nul.Nullable[int]
}{
{
Nullable: nul.Nothing[int](),
Expected: nul.Nothing[int](),
},
{
Nullable: nul.Something[int](-2),
Expected: nul.Something[int](-2),
},
{
Nullable: nul.Something[int](-1),
Expected: nul.Nothing[int](),
},
{
Nullable: nul.Something[int](0),
Expected: nul.Something[int](0),
},
{
Nullable: nul.Something[int](1),
Expected: nul.Nothing[int](),
},
{
Nullable: nul.Something[int](2),
Expected: nul.Something[int](2),
},
}
for testNumber, test := range tests {
fn := func(value int) bool {
return 0 == (value % 2)
}
actual := test.Nullable.Filter(fn)
expected := test.Expected
if expected != actual {
t.Errorf("For test #%d, the actual value is not what was expected.", testNumber)
t.Logf("EXPECTED: %#v", expected)
t.Logf("ACTUAL: %#v", actual)
/////////////// CONTINUE
continue
}
}
}