2025-11-06 09:27:00 +01:00
|
|
|
package either
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2025-11-15 17:00:22 +01:00
|
|
|
A "github.com/IBM/fp-go/v2/array"
|
2025-11-06 09:27:00 +01:00
|
|
|
TST "github.com/IBM/fp-go/v2/internal/testing"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCompactArray(t *testing.T) {
|
2025-11-15 17:00:22 +01:00
|
|
|
ar := A.From(
|
2025-11-06 09:27:00 +01:00
|
|
|
Of[string]("ok"),
|
|
|
|
|
Left[string]("err"),
|
|
|
|
|
Of[string]("ok"),
|
2025-11-15 17:00:22 +01:00
|
|
|
)
|
2025-11-06 09:27:00 +01:00
|
|
|
|
|
|
|
|
res := CompactArray(ar)
|
|
|
|
|
assert.Equal(t, 2, len(res))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSequenceArray(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
s := TST.SequenceArrayTest(
|
|
|
|
|
FromStrictEquals[error, bool](),
|
|
|
|
|
Pointed[error, string](),
|
|
|
|
|
Pointed[error, bool](),
|
|
|
|
|
Functor[error, []string, bool](),
|
|
|
|
|
SequenceArray[error, string],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
t.Run(fmt.Sprintf("TestSequenceArray %d", i), s(i))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSequenceArrayError(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
s := TST.SequenceArrayErrorTest(
|
|
|
|
|
FromStrictEquals[error, bool](),
|
|
|
|
|
Left[string, error],
|
|
|
|
|
Left[bool, error],
|
|
|
|
|
Pointed[error, string](),
|
|
|
|
|
Pointed[error, bool](),
|
|
|
|
|
Functor[error, []string, bool](),
|
|
|
|
|
SequenceArray[error, string],
|
|
|
|
|
)
|
|
|
|
|
// run across four bits
|
|
|
|
|
s(4)(t)
|
|
|
|
|
}
|