Skip to content

Commit fdff4e4

Browse files
committed
fix: more tests
Signed-off-by: Dr. Carsten Leue <[email protected]>
1 parent 391754e commit fdff4e4

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

internal/testing/sequence.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,41 @@ func SequenceArrayErrorTest[
143143
}
144144
}
145145
}
146+
147+
// SequenceRecordTest tests if the sequence operation works in case the operation cannot error
148+
func SequenceRecordTest[
149+
HKTA,
150+
HKTB,
151+
HKTAA any, // HKT[map[string]string]
152+
](
153+
eq EQ.Eq[HKTB],
154+
155+
pa pointed.Pointed[string, HKTA],
156+
pb pointed.Pointed[bool, HKTB],
157+
faa functor.Functor[map[string]string, bool, HKTAA, HKTB],
158+
seq func(map[string]HKTA) HKTAA,
159+
) func(count int) func(t *testing.T) {
160+
161+
return func(count int) func(t *testing.T) {
162+
163+
exp := make(map[string]string)
164+
good := make(map[string]HKTA)
165+
for i := 0; i < count; i++ {
166+
key := fmt.Sprintf("KeyData %d", i)
167+
val := fmt.Sprintf("ValueData %d", i)
168+
exp[key] = val
169+
good[key] = pa.Of(val)
170+
}
171+
172+
return func(t *testing.T) {
173+
res := F.Pipe2(
174+
good,
175+
seq,
176+
faa.Map(func(act map[string]string) bool {
177+
return assert.Equal(t, exp, act)
178+
}),
179+
)
180+
assert.True(t, eq.Equals(res, pb.Of(true)))
181+
}
182+
}
183+
}

option/record_test.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,13 @@
1616
package option
1717

1818
import (
19+
"fmt"
1920
"testing"
2021

22+
TST "github.com/IBM/fp-go/internal/testing"
2123
"github.com/stretchr/testify/assert"
2224
)
2325

24-
func TestSequenceRecord(t *testing.T) {
25-
assert.Equal(t, Of(map[string]string{
26-
"a": "A",
27-
"b": "B",
28-
}), SequenceRecord(map[string]Option[string]{
29-
"a": Of("A"),
30-
"b": Of("B"),
31-
}))
32-
}
33-
3426
func TestCompactRecord(t *testing.T) {
3527
// make the map
3628
m := make(map[string]Option[int])
@@ -45,3 +37,18 @@ func TestCompactRecord(t *testing.T) {
4537

4638
assert.Equal(t, exp, m1)
4739
}
40+
41+
func TestSequenceRecord(t *testing.T) {
42+
43+
s := TST.SequenceRecordTest(
44+
FromStrictEquals[bool](),
45+
Pointed[string](),
46+
Pointed[bool](),
47+
Functor[map[string]string, bool](),
48+
SequenceRecord[string, string],
49+
)
50+
51+
for i := 0; i < 10; i++ {
52+
t.Run(fmt.Sprintf("TestSequenceRecord %d", i), s(i))
53+
}
54+
}

0 commit comments

Comments
 (0)