Skip to content

Commit

Permalink
Replicate sorted test to NEV and NES
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Sep 6, 2017
1 parent ed75575 commit e1d39b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/src/test/scala/cats/tests/NonEmptyVectorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,20 @@ class NonEmptyVectorTests extends CatsSuite {
}
}


test("NonEmptyVector#zipWith is consistent with Vector#zip and then Vector#map") {
forAll { (a: NonEmptyVector[Int], b: NonEmptyVector[Int], f: (Int, Int) => Int) =>
a.zipWith(b)(f).toVector should === (a.toVector.zip(b.toVector).map { case (x, y) => f(x, y)})
a.zipWith(b)(f).toVector should ===(a.toVector.zip(b.toVector).map { case (x, y) => f(x, y) })
}
}
test("NonEmptyVector#nonEmptyPartition remains sorted") {
forAll { (nev: NonEmptyVector[Int], f: Int => Either[String, String]) =>

val sorted = NonEmptyVector.fromVectorUnsafe(nev.map(f).toVector.sorted)
val ior = Reducible[NonEmptyVector].nonEmptyPartition(sorted)(identity)

ior.left.map(xs => xs.sorted should === (xs))
ior.right.map(xs => xs.sorted should === (xs))
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/src/test/scala/cats/tests/OneAndTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ class OneAndTests extends CatsSuite {
}
}

test("NonEmptyStream#nonEmptyPartition remains sorted") {
forAll { (nes: NonEmptyStream[Int], f: Int => Either[String, String]) =>

val nesf = nes.map(f)
val sortedStream = (nesf.head #:: nesf.tail).sorted
val sortedNes = OneAnd(sortedStream.head, sortedStream.tail)
val ior = Reducible[NonEmptyStream].nonEmptyPartition(sortedNes)(identity)

ior.left.map(xs => xs.sorted should === (xs))
ior.right.map(xs => xs.sorted should === (xs))
}
}

test("reduceLeft consistent with foldLeft") {
forAll { (nel: NonEmptyStream[Int], f: (Int, Int) => Int) =>
nel.reduceLeft(f) should === (nel.tail.foldLeft(nel.head)(f))
Expand Down

0 comments on commit e1d39b1

Please sign in to comment.