mirror of
https://github.com/IBM/fp-go.git
synced 2025-07-07 00:57:11 +02:00
fix: more tests
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@ -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)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -16,21 +16,13 @@
|
|||||||
package option
|
package option
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
TST "github.com/IBM/fp-go/internal/testing"
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestCompactRecord(t *testing.T) {
|
||||||
// make the map
|
// make the map
|
||||||
m := make(map[string]Option[int])
|
m := make(map[string]Option[int])
|
||||||
@ -45,3 +37,18 @@ func TestCompactRecord(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, exp, m1)
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user