2023-09-23 22:59:33 +00:00
|
|
|
package nul_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-08-01 23:28:38 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|