@@ -7,6 +7,12 @@ import org.junit.runner.RunWith
7
7
8
8
@RunWith(KTestJUnitRunner ::class )
9
9
class OptionTTest : UnitSpec () {
10
+ val EQ_ID : Eq <HK <OptionTKindPartial <IdHK >, Int >> = Eq { a, b ->
11
+ a.value() == b.value()
12
+ }
13
+
14
+ val NELM : Monad <NonEmptyListHK > = monad<NonEmptyListHK >()
15
+
10
16
init {
11
17
12
18
" instances can be resolved implicitly" {
@@ -20,51 +26,44 @@ class OptionTTest : UnitSpec() {
20
26
functorFilter<OptionTKindPartial <ListKWHK >>() shouldNotBe null
21
27
}
22
28
23
- val OptionTFIdEq = object : Eq <HK <OptionTKindPartial <IdHK >, Int >> {
24
- override fun eqv (a : HK <OptionTKindPartial <IdHK >, Int >, b : HK <OptionTKindPartial <IdHK >, Int >): Boolean =
25
- a.ev().value == b.ev().value
26
- }
27
-
28
29
testLaws(MonadLaws .laws(OptionT .monad(NonEmptyList .monad()), Eq .any()))
29
30
testLaws(TraverseLaws .laws(OptionT .traverse(), OptionT .applicative(Id .monad()), { OptionT (Id (it.some())) }, Eq .any()))
30
31
testLaws(SemigroupKLaws .laws(
31
32
OptionT .semigroupK(Id .monad()),
32
33
OptionT .applicative(Id .monad()),
33
- OptionTFIdEq ))
34
+ EQ_ID ))
34
35
35
36
testLaws(MonoidKLaws .laws(
36
37
OptionT .monoidK(Id .monad()),
37
38
OptionT .applicative(Id .monad()),
38
- OptionTFIdEq ))
39
+ EQ_ID ))
39
40
40
41
testLaws(FunctorFilterLaws .laws(
41
42
OptionT .functorFilter(),
42
43
{ OptionT (Id (it.some())) },
43
- OptionTFIdEq ))
44
-
45
- val nelMonad = monad<NonEmptyListHK >()
44
+ EQ_ID ))
46
45
47
46
" toLeft for Some should build a correct EitherT" {
48
47
forAll { a: Int , b: String ->
49
- OptionT .fromOption<NonEmptyListHK , Int >(Option .Some (a)).toLeft({ b }, nelMonad ) == EitherT .left<NonEmptyListHK , Int , String >(a, applicative())
48
+ OptionT .fromOption<NonEmptyListHK , Int >(Option .Some (a)).toLeft({ b }, NELM ) == EitherT .left<NonEmptyListHK , Int , String >(a, applicative())
50
49
}
51
50
}
52
51
53
52
" toLeft for None should build a correct EitherT" {
54
53
forAll { a: Int , b: String ->
55
- OptionT .fromOption<NonEmptyListHK , Int >(Option .None ).toLeft({ b }, nelMonad ) == EitherT .right<NonEmptyListHK , Int , String >(b, applicative())
54
+ OptionT .fromOption<NonEmptyListHK , Int >(Option .None ).toLeft({ b }, NELM ) == EitherT .right<NonEmptyListHK , Int , String >(b, applicative())
56
55
}
57
56
}
58
57
59
58
" toRight for Some should build a correct EitherT" {
60
59
forAll { a: Int , b: String ->
61
- OptionT .fromOption<NonEmptyListHK , String >(Option .Some (b)).toRight({ a }, nelMonad ) == EitherT .right<NonEmptyListHK , Int , String >(b, applicative())
60
+ OptionT .fromOption<NonEmptyListHK , String >(Option .Some (b)).toRight({ a }, NELM ) == EitherT .right<NonEmptyListHK , Int , String >(b, applicative())
62
61
}
63
62
}
64
63
65
64
" toRight for None should build a correct EitherT" {
66
65
forAll { a: Int , b: String ->
67
- OptionT .fromOption<NonEmptyListHK , String >(Option .None ).toRight({ a }, nelMonad ) == EitherT .left<NonEmptyListHK , Int , String >(a, applicative())
66
+ OptionT .fromOption<NonEmptyListHK , String >(Option .None ).toRight({ a }, NELM ) == EitherT .left<NonEmptyListHK , Int , String >(a, applicative())
68
67
}
69
68
}
70
69
0 commit comments