@@ -11,12 +11,13 @@ import fj.data.ArbitraryNonEmptyList.arbitraryNonEmptyList
1111import fj .data .ArbitraryOption .arbitraryOption
1212import fj .data .ArbitrarySet .arbitrarySet
1313import fj .data .ArbitraryStream .arbitraryStream
14+ import fj .data .IO
1415import org .scalacheck .Arbitrary ._
1516import org .scalacheck .Prop ._
1617import org .scalacheck .{Arbitrary , Properties }
1718
1819/**
19- * Scalacheck [[Properties ]] for [[Semigroup ]] implementations.
20+ * Scalacheck [[Properties ]] parameterized for [[Semigroup ]] implementations.
2021 *
2122 * @param s a Semigroup implementation.
2223 * @param desc a description of the Semigroup implementation.
@@ -44,9 +45,59 @@ case class SemigroupProperties[T](s: Semigroup[T], desc: String)(implicit val ar
4445
4546}
4647
48+ /**
49+ * A specialized Scalacheck [[Properties ]] object for testing the [[Semigroup.ioSemigroup() ]] method.
50+ */
51+ object CheckIOSemigroup extends Properties (" ioSemigroup" ) {
52+
53+ val s = Semigroup .ioSemigroup(Semigroup .stringSemigroup)
54+
55+ property(" sum(x,y)" ) = forAll((x : IO [String ], y : IO [String ], z : IO [String ]) =>
56+ s.sum(s.sum(x, y), z).run() == s.sum(x, s.sum(y, z)).run())
57+
58+ property(" sum()" ) = forAll((x : IO [String ], y : IO [String ], z : IO [String ]) => {
59+ val sf = s.sum()
60+ sf.f(sf.f(x).f(y)).f(z).run() == sf.f(x).f(sf.f(y).f(z)).run()
61+ })
62+
63+ property(" dual()" ) = forAll((x : IO [String ], y : IO [String ], z : IO [String ]) => {
64+ val sd = s.dual()
65+ sd.sum(sd.sum(x, y), z).run() == sd.sum(x, sd.sum(y, z)).run()
66+ })
67+
68+ property(" sum(x)" ) = forAll((x : IO [String ], y : IO [String ]) =>
69+ s.sum(x).f(y).run() == s.sum(x, y).run())
70+
71+ }
72+
73+ object CheckStringBuilder extends Properties (" stringBuilderSemigroup" ) {
74+
75+ val s : Semigroup [java.lang.StringBuilder ] = Semigroup .stringBuilderSemigroup
76+
77+ implicit def toStringBuilder (str : String ): java.lang.StringBuilder = new java.lang.StringBuilder (str)
78+
79+ property(" sum(x,y)" ) = forAll((x : String , y : String , z : String ) =>
80+ s.sum(s.sum(x, y), z).toString == s.sum(x, s.sum(y, z)).toString
81+ )
82+
83+ property(" sum()" ) = forAll((x : String , y : String , z : String ) => {
84+ val sf = s.sum()
85+ sf.f(sf.f(x).f(y)).f(z).toString == sf.f(x).f(sf.f(y).f(z.toString))
86+ })
87+
88+ property(" dual()" ) = forAll((x : String , y : String , z : String ) => {
89+ val sd = s.dual()
90+ sd.sum(sd.sum(x, y), z).toString == sd.sum(x, sd.sum(y, z).toString)
91+ })
92+
93+ property(" sum(x)" ) = forAll((x : String , y : String ) =>
94+ s.sum(x).f(y).toString == s.sum(x, y).toString)
95+
96+ }
97+
4798
4899/**
49- *
100+ * A Scalacheck [[ Properties ]] object that aggregates the tests for all [[ Semigroup ]] implementations.
50101 */
51102object CheckSemigroup extends Properties (" Semigroup" ) {
52103
@@ -107,7 +158,7 @@ object CheckSemigroup extends Properties("Semigroup") {
107158 include(SemigroupProperties (Semigroup .intMaximumSemigroup, " intMaximumSemigroup" ))
108159 include(SemigroupProperties (Semigroup .intMinimumSemigroup, " intMinimumSemigroup" ))
109160
110- include(SemigroupProperties ( Semigroup .ioSemigroup[ String ]( Semigroup .stringSemigroup), " ioSemigroup(Semigroup) " ) )
161+ include(CheckIOSemigroup )
111162
112163 include(SemigroupProperties (Semigroup .lastOptionSemigroup[Int ](), " lastOptionSemigroup()" ))
113164 include(SemigroupProperties (Semigroup .lastSemigroup[Int ](), " lastSemigroup()" ))
0 commit comments