1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-07-09 01:05:51 +02:00
Files
fp-go/internal/testing/sequence.go
Dr. Carsten Leue 598a7b261b fix: add more tests
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2024-05-24 23:19:24 +02:00

65 lines
1.6 KiB
Go

// Copyright (c) 2023 IBM Corp.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package testing
import (
"fmt"
"testing"
EQ "github.com/IBM/fp-go/eq"
F "github.com/IBM/fp-go/function"
"github.com/IBM/fp-go/internal/functor"
"github.com/IBM/fp-go/internal/pointed"
"github.com/stretchr/testify/assert"
)
// SequenceArrayTest tests if the sequence operation works in case the operation cannot error
func SequenceArrayTest[
HKTA,
HKTB,
HKTAA any, // HKT[[]A]
](
eq EQ.Eq[HKTB],
pa pointed.Pointed[string, HKTA],
pb pointed.Pointed[bool, HKTB],
faa functor.Functor[[]string, bool, HKTAA, HKTB],
seq func([]HKTA) HKTAA,
) func(count int) func(t *testing.T) {
return func(count int) func(t *testing.T) {
exp := make([]string, count)
good := make([]HKTA, count)
for i := 0; i < count; i++ {
val := fmt.Sprintf("TestData %d", i)
exp[i] = val
good[i] = pa.Of(val)
}
return func(t *testing.T) {
res := F.Pipe2(
good,
seq,
faa.Map(func(act []string) bool {
return assert.Equal(t, exp, act)
}),
)
assert.True(t, eq.Equals(res, pb.Of(true)))
}
}
}