Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]()
}

}