Skip to content

Commit 0f86399

Browse files
author
ivan
committed
fix time function
1 parent 5b3ad97 commit 0f86399

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

scala/src/test/scala/ch11_sorts/SortsTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ class SortsTest extends FlatSpec with Matchers {
4747
array(i) = rnd.nextInt()
4848
}
4949

50-
timed("bubbleSort", Sorts.bubbleSort(array.clone()))
51-
timed("insertSort", Sorts.bubbleSort(array.clone()))
52-
timed("selectionSort", Sorts.bubbleSort(array.clone()))
50+
timed("bubbleSort", Sorts.bubbleSort, array.clone())
51+
timed("insertSort", Sorts.insertSort, array.clone())
52+
timed("selectionSort", Sorts.selectionSort, array.clone())
5353
}
5454

5555
def reportElapsed(name: String, time: Long): Unit = println(name + " takes in " + time + "ms")
5656

57-
def timed[T](name: String, f: => T): T = {
57+
def timed[T](name: String, f: (Array[Int]) => T, array: Array[Int]): T = {
5858
val start = System.currentTimeMillis()
59-
try f finally reportElapsed(name, System.currentTimeMillis - start)
59+
try f(array) finally reportElapsed(name, System.currentTimeMillis - start)
6060
}
6161
}

0 commit comments

Comments
 (0)