From 75ce3572497e0faedd96d89ad69bc3595f91f9d2 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 24 Sep 2023 07:59:33 +0900 Subject: [PATCH] initial commits --- nullable_filter_test.go | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 nullable_filter_test.go diff --git a/nullable_filter_test.go b/nullable_filter_test.go new file mode 100644 index 0000000..8af3712 --- /dev/null +++ b/nullable_filter_test.go @@ -0,0 +1,61 @@ +package nul_test + +import ( + "testing" + + "sourcecode.social/reiver/go-nul" +) + +func TestOptional_Filter_int(t *testing.T) { + + 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 + } + } +}