Skip to content

Commit

Permalink
Merge pull request #167 from xirc/throws-unsupported-operation-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue authored Mar 23, 2021
2 parents 013eb07 + e578b77 commit 7bc6f6e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ extends IterableOnce[T @uncheckedVariance]
* if this $coll is empty.
*/
def reduce[U >: T](op: (U, U) => U): U = {
if (isEmpty) throw new UnsupportedOperationException("empty.reduce")

tasksupport.executeAndWaitResult(new Reduce(op, splitter)).get
}

Expand Down Expand Up @@ -463,10 +465,14 @@ extends IterableOnce[T @uncheckedVariance]
}

def min[U >: T](implicit ord: Ordering[U]): T = {
if (isEmpty) throw new UnsupportedOperationException("empty.min")

tasksupport.executeAndWaitResult(new Min(ord, splitter)).get.asInstanceOf[T]
}

def max[U >: T](implicit ord: Ordering[U]): T = {
if (isEmpty) throw new UnsupportedOperationException("empty.max")

tasksupport.executeAndWaitResult(new Max(ord, splitter)).get.asInstanceOf[T]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class ParArrayTest extends scala.collection.concurrent.ctries_old.Spec {
assert( ParArray(1,2,3,4,5).reduce(_+_) == 15 )
}

@Test
def `empty reduce`: Unit = {
evaluating { ParArray.empty[Int].reduce(_+_) }.shouldProduce[UnsupportedOperationException]()
}

@Test
def `simple count`: Unit = {
assert( ParArray[Int]().count(_ > 7) == 0 )
Expand Down Expand Up @@ -127,4 +132,25 @@ class ParArrayTest extends scala.collection.concurrent.ctries_old.Spec {
def `simple map test`: Unit = {
assert(ParArray(1,2,3,4,5).map( (_:Int) * 10 ) == ParArray(10,20,30,40,50))
}

@Test
def `empty min`: Unit = {
evaluating { ParArray.empty[Int].min }.shouldProduce[UnsupportedOperationException]()
}

@Test
def `empty max`: Unit = {
evaluating { ParArray.empty[Int].max }.shouldProduce[UnsupportedOperationException]()
}

@Test
def `empty minBy`: Unit = {
evaluating { ParArray.empty[String].minBy(_.length) }.shouldProduce[UnsupportedOperationException]()
}

@Test
def `emtpy maxBy`: Unit = {
evaluating { ParArray.empty[String].maxBy(_.length) }.shouldProduce[UnsupportedOperationException]()
}

}

0 comments on commit 7bc6f6e

Please sign in to comment.