Skip to content

Commit

Permalink
fix: more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
  • Loading branch information
CarstenLeue committed May 26, 2024
1 parent 391754e commit fdff4e4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
38 changes: 38 additions & 0 deletions internal/testing/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}
}
27 changes: 17 additions & 10 deletions option/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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))
}
}

0 comments on commit fdff4e4

Please sign in to comment.