You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

#### 36 lines 1.0 KiB Raw Permalink Blame History

 `package green.thisfieldwas.embracingnondeterminism.stdlib` ``` ``` `import green.thisfieldwas.embracingnondeterminism.data.{Semigroup, SemigroupLaws}` `import green.thisfieldwas.embracingnondeterminism.util.Laws` `import org.scalacheck.{Arbitrary, Gen}` `import Arbitrary.arbitrary` ``` ``` `/** Proves that Scala's Set conforms to a Semigroup.` ` */` `class SetSpec extends Laws with SemigroupLaws {` ``` ``` ` /** Non-empty Sets specifically form Semigroups.` ` *` ` * @tparam A` ` * Any type held by a Set.` ` * @return` ` * The Arbitrary generator for a non-empty Set.` ` */` ` implicit def arbitraryNonEmptySet[A: Arbitrary]: Arbitrary[Set[A]] = Arbitrary {` ` for {` ` length <- Gen.sized(n => Gen.choose(1, n.max(1)))` ` set <- Gen.listOfN(length, arbitrary[A]).map(_.toSet)` ` } yield set` ` }` ``` ``` ` /** Set forms a Semigroup under union.` ` *` ` * @tparam A` ` * Any type held by the Set.` ` * @return` ` * The Semigroup instance for Set.` ` */` ` implicit def setSemigroup[A]: Semigroup[Set[A]] = _.union(_)` ``` ``` ` checkSemigroupLaws[Set[Int]]()` ```} ``` ``` ```