diff --git a/internal/testing/sequence.go b/internal/testing/sequence.go index 2d66d26..4e7604b 100644 --- a/internal/testing/sequence.go +++ b/internal/testing/sequence.go @@ -143,3 +143,41 @@ func SequenceArrayErrorTest[ } } } + +// SequenceRecordTest tests if the sequence operation works in case the operation cannot error +func SequenceRecordTest[ + HKTA, + HKTB, + HKTAA any, // HKT[map[string]string] +]( + eq EQ.Eq[HKTB], + + pa pointed.Pointed[string, HKTA], + pb pointed.Pointed[bool, HKTB], + faa functor.Functor[map[string]string, bool, HKTAA, HKTB], + seq func(map[string]HKTA) HKTAA, +) func(count int) func(t *testing.T) { + + return func(count int) func(t *testing.T) { + + exp := make(map[string]string) + good := make(map[string]HKTA) + for i := 0; i < count; i++ { + key := fmt.Sprintf("KeyData %d", i) + val := fmt.Sprintf("ValueData %d", i) + exp[key] = val + good[key] = pa.Of(val) + } + + return func(t *testing.T) { + res := F.Pipe2( + good, + seq, + faa.Map(func(act map[string]string) bool { + return assert.Equal(t, exp, act) + }), + ) + assert.True(t, eq.Equals(res, pb.Of(true))) + } + } +} diff --git a/option/record_test.go b/option/record_test.go index b6f5640..92186ff 100644 --- a/option/record_test.go +++ b/option/record_test.go @@ -16,21 +16,13 @@ package option import ( + "fmt" "testing" + TST "github.com/IBM/fp-go/internal/testing" "github.com/stretchr/testify/assert" ) -func TestSequenceRecord(t *testing.T) { - assert.Equal(t, Of(map[string]string{ - "a": "A", - "b": "B", - }), SequenceRecord(map[string]Option[string]{ - "a": Of("A"), - "b": Of("B"), - })) -} - func TestCompactRecord(t *testing.T) { // make the map m := make(map[string]Option[int]) @@ -45,3 +37,18 @@ func TestCompactRecord(t *testing.T) { assert.Equal(t, exp, m1) } + +func TestSequenceRecord(t *testing.T) { + + s := TST.SequenceRecordTest( + FromStrictEquals[bool](), + Pointed[string](), + Pointed[bool](), + Functor[map[string]string, bool](), + SequenceRecord[string, string], + ) + + for i := 0; i < 10; i++ { + t.Run(fmt.Sprintf("TestSequenceRecord %d", i), s(i)) + } +}