go-opt/optional_issomething_int_te...

92 lines
1.4 KiB
Go
Raw Permalink Normal View History

package opt_test
import (
"testing"
2024-07-04 16:54:41 +00:00
"github.com/reiver/go-opt"
)
func TestOptional_IsSomething_int(t *testing.T) {
tests := []struct{
Optional opt.Optional[int]
Expected bool
}{
{
Optional: opt.Nothing[int](),
Expected: false,
},
{
Optional: opt.Something(-255),
Expected: true,
},
{
Optional: opt.Something(-5),
Expected: true,
},
{
Optional: opt.Something(-4),
Expected: true,
},
{
Optional: opt.Something(-3),
Expected: true,
},
{
Optional: opt.Something(-2),
Expected: true,
},
{
Optional: opt.Something(-1),
Expected: true,
},
{
Optional: opt.Something(0),
Expected: true,
},
{
Optional: opt.Something(1),
Expected: true,
},
{
Optional: opt.Something(2),
Expected: true,
},
{
Optional: opt.Something(3),
Expected: true,
},
{
Optional: opt.Something(4),
Expected: true,
},
{
Optional: opt.Something(5),
Expected: true,
},
{
Optional: opt.Something(255),
Expected: true,
},
}
for testNumber, test := range tests {
actual := test.Optional.IsSomething()
expected := test.Expected
if expected != actual {
t.Errorf("For test #%d, the actual value of is-something it not what was expected.", testNumber)
t.Logf("EXPECTED: %t", expected)
t.Logf("ACTUAL: %t", actual)
t.Logf("OPTIONAL: %#v", test.Optional)
continue
}
}
}