From 40194dae870a31070a29badcc05a413f603f50f7 Mon Sep 17 00:00:00 2001 From: "Kai(luo) Wang" Date: Sat, 8 Apr 2017 07:19:53 -0400 Subject: [PATCH] added instances of BitSet to allInstances (#1592) * added instances of BitSet to allInstances * unnecessary show implementation * removed unused imports --- core/src/main/scala/cats/instances/all.scala | 1 + .../main/scala/cats/instances/bitSet.scala | 8 +++++++ .../main/scala/cats/instances/package.scala | 1 + .../test/scala/cats/tests/BitSetTests.scala | 21 +++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 core/src/main/scala/cats/instances/bitSet.scala create mode 100644 tests/src/test/scala/cats/tests/BitSetTests.scala diff --git a/core/src/main/scala/cats/instances/all.scala b/core/src/main/scala/cats/instances/all.scala index 18068be967..586d5f287d 100644 --- a/core/src/main/scala/cats/instances/all.scala +++ b/core/src/main/scala/cats/instances/all.scala @@ -14,6 +14,7 @@ trait AllInstances with MapInstances with BigIntInstances with BigDecimalInstances + with BitSetInstances with FutureInstances with TryInstances with TupleInstances diff --git a/core/src/main/scala/cats/instances/bitSet.scala b/core/src/main/scala/cats/instances/bitSet.scala new file mode 100644 index 0000000000..dc14fe8276 --- /dev/null +++ b/core/src/main/scala/cats/instances/bitSet.scala @@ -0,0 +1,8 @@ +package cats.instances + +import scala.collection.immutable.BitSet +import cats.Show + +trait BitSetInstances extends cats.kernel.instances.BitSetInstances { + implicit def catsStdShowForBitSet: Show[BitSet] = Show.fromToString[BitSet] +} diff --git a/core/src/main/scala/cats/instances/package.scala b/core/src/main/scala/cats/instances/package.scala index 8f1a10cad3..d08087f022 100644 --- a/core/src/main/scala/cats/instances/package.scala +++ b/core/src/main/scala/cats/instances/package.scala @@ -9,6 +9,7 @@ package object instances { object list extends ListInstances object option extends OptionInstances object set extends SetInstances + object bitSet extends BitSetInstances object stream extends StreamInstances object vector extends VectorInstances object map extends MapInstances diff --git a/tests/src/test/scala/cats/tests/BitSetTests.scala b/tests/src/test/scala/cats/tests/BitSetTests.scala new file mode 100644 index 0000000000..ac79dc764c --- /dev/null +++ b/tests/src/test/scala/cats/tests/BitSetTests.scala @@ -0,0 +1,21 @@ +package cats.tests + +import org.scalacheck.Arbitrary +import org.scalacheck.Arbitrary.arbitrary + +import scala.collection.immutable.BitSet + +class BitSetTests extends CatsSuite { + implicit val arbitraryBitSet: Arbitrary[BitSet] = + Arbitrary(arbitrary[List[Short]].map(ns => BitSet(ns.map(_ & 0xffff): _*))) + + test("show BitSet"){ + BitSet(1, 1, 2, 3).show should === ("BitSet(1, 2, 3)") + BitSet.empty.show should === ("BitSet()") + + forAll { fs: BitSet => + fs.show should === (fs.toString) + } + } + +}