2022-08-14 07:58:41 +00:00
|
|
|
package opt_test
|
|
|
|
|
|
|
|
import (
|
2024-07-04 16:54:41 +00:00
|
|
|
"github.com/reiver/go-opt"
|
2022-08-14 07:58:41 +00:00
|
|
|
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestOptional_Filter_int(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct{
|
|
|
|
Optional opt.Optional[int]
|
|
|
|
Expected opt.Optional[int]
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Optional: opt.Nothing[int](),
|
|
|
|
Expected: opt.Nothing[int](),
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
Optional: opt.Something[int](-2),
|
|
|
|
Expected: opt.Something[int](-2),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Optional: opt.Something[int](-1),
|
|
|
|
Expected: opt.Nothing[int](),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Optional: opt.Something[int](0),
|
|
|
|
Expected: opt.Something[int](0),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Optional: opt.Something[int](1),
|
|
|
|
Expected: opt.Nothing[int](),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Optional: opt.Something[int](2),
|
|
|
|
Expected: opt.Something[int](2),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for testNumber, test := range tests {
|
|
|
|
|
|
|
|
fn := func(value int) bool {
|
|
|
|
return 0 == (value % 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := test.Optional.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|