Skip to content

Commit

Permalink
Merge pull request #1062 from mpilquist/bugfix/tuple-order-bug
Browse files Browse the repository at this point in the history
Fixed a bug in the Order and PartialOrder instances for Tuple2+ where only the first element was used in comparisons
  • Loading branch information
ceedubs committed May 25, 2016
2 parents 8fefdff + 42cb7ba commit 011fc52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions project/KernelBoiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ object KernelBoiler {
- implicit def tuple${arity}Order[${`A..N`}](implicit ${constraints("Order")}): Order[${`(A..N)`}] =
- new Order[${`(A..N)`}] {
- def compare(x: ${`(A..N)`}, y: ${`(A..N)`}): Int =
- ${binMethod("compare").find(_ != 0).getOrElse(0)}
- ${binMethod("compare").mkString("Array(", ", ", ")")}.find(_ != 0).getOrElse(0)
- }
-
- implicit def tuple${arity}PartialOrder[${`A..N`}](implicit ${constraints("PartialOrder")}): PartialOrder[${`(A..N)`}] =
- new PartialOrder[${`(A..N)`}] {
- def partialCompare(x: ${`(A..N)`}, y: ${`(A..N)`}): Double =
- ${binMethod("partialCompare").find(_ != 0.0).getOrElse(0.0)}
- ${binMethod("partialCompare").mkString("Array(", ", ", ")")}.find(_ != 0.0).getOrElse(0.0)
- }
-
- implicit def tuple${arity}Semigroup[${`A..N`}](implicit ${constraints("Semigroup")}): Semigroup[${`(A..N)`}] =
Expand Down
13 changes: 13 additions & 0 deletions tests/src/test/scala/cats/tests/TupleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ class TupleTests extends CatsSuite {
checkAll("Tuple2", BitraverseTests[Tuple2].bitraverse[Option, Int, Int, Int, String, String, String])
checkAll("Bitraverse[Tuple2]", SerializableTests.serializable(Bitraverse[Tuple2]))

test("eqv") {
val eq = Eq[(Int, Long)]
forAll { t: (Int, Long) => eq.eqv(t, t) should === (true) }
forAll { t: (Int, Long) => eq.eqv(t, t._1 -> (t._2 + 1)) should === (false) }
}

test("order") {
forAll { t: (Int, Int) =>
val u = t.swap
Order[(Int, Int)].compare(t, u) should === (scala.math.Ordering[(Int, Int)].compare(t, u))
}
}

test("show") {
(1, 2).show should === ("(1,2)")

Expand Down

0 comments on commit 011fc52

Please sign in to comment.