@@ -9,18 +9,18 @@ class AbstractAlgebraTest extends CheckProperties with Matchers {
9
9
10
10
property(" A Monoid should be able to sum" ) {
11
11
val monoid = implicitly[Monoid [Int ]]
12
- forAll { intList : List [Int ] => intList.sum == monoid.sum(intList) }
12
+ forAll(( intList : List [Int ]) => intList.sum == monoid.sum(intList))
13
13
}
14
14
15
15
property(" A Ring should be able to product" ) {
16
16
val ring = implicitly[Ring [Int ]]
17
- forAll { intList : List [Int ] => intList.product == ring.product(intList) }
17
+ forAll(( intList : List [Int ]) => intList.product == ring.product(intList))
18
18
}
19
19
20
20
property(" An OptionMonoid should be able to sum" ) {
21
21
val monoid = implicitly[Monoid [Option [Int ]]]
22
22
23
- forAll { intList : List [Option [Int ]] =>
23
+ forAll { ( intList : List [Option [Int ]]) =>
24
24
val flattenedList = intList.flatten
25
25
val expectedResult =
26
26
if (flattenedList.nonEmpty) Some (flattenedList.sum) else None
@@ -31,7 +31,7 @@ class AbstractAlgebraTest extends CheckProperties with Matchers {
31
31
property(" An OptionMonoid based on a Semigroup should be able to sum" ) {
32
32
val maxMonoid = implicitly[Monoid [Option [Max [Int ]]]]
33
33
val minMonoid = implicitly[Monoid [Option [Min [Int ]]]]
34
- forAll { intList : List [Option [Int ]] =>
34
+ forAll { ( intList : List [Option [Int ]]) =>
35
35
val minList = intList.map {
36
36
case Some (x) => Some (Min (x))
37
37
case None => None
@@ -84,7 +84,7 @@ class AbstractAlgebraTest extends CheckProperties with Matchers {
84
84
85
85
property(" An ArrayMonoid should sum" ) {
86
86
val monoid = new ArrayMonoid [Int ]
87
- forAll { intList : List [Int ] =>
87
+ forAll { ( intList : List [Int ]) =>
88
88
val (l, r) = intList.splitAt(intList.size / 2 )
89
89
val left = l.padTo(math.max(l.size, r.size), 0 )
90
90
val right = r.padTo(math.max(l.size, r.size), 0 )
@@ -97,7 +97,7 @@ class AbstractAlgebraTest extends CheckProperties with Matchers {
97
97
98
98
property(" An ArrayGroup should negate" ) {
99
99
val arrayGroup = new ArrayGroup [Int ]
100
- forAll { intList : List [Int ] =>
100
+ forAll { ( intList : List [Int ]) =>
101
101
intList.map(- 1 * _).toSeq == arrayGroup
102
102
.negate(intList.toArray)
103
103
.toSeq
@@ -106,8 +106,12 @@ class AbstractAlgebraTest extends CheckProperties with Matchers {
106
106
107
107
property(" a user-defined product monoid should work" ) {
108
108
case class Metrics (count : Int , largestValue : Option [Max [Int ]])
109
- implicit val MetricsMonoid = Monoid (Metrics .apply _, Metrics .unapply _)
110
- implicit val metricsGen = Arbitrary {
109
+ val unapply : Metrics => Option [(Int , Option [Max [Int ]])] = { case Metrics (count, largestValue) =>
110
+ Some ((count, largestValue))
111
+ }
112
+ implicit val MetricsMonoid : Monoid [Metrics ] =
113
+ Monoid .apply[Metrics , Int , Option [Max [Int ]]](Metrics .apply _, unapply)
114
+ implicit val metricsGen : Arbitrary [Metrics ] = Arbitrary [Metrics ] {
111
115
for {
112
116
count <- Gen .choose(0 , 10000 )
113
117
largest <- Gen .oneOf[Option [Max [Int ]]](None , Gen .choose(1 , 100 ).map(n => Some (Max (n))))
0 commit comments