-
Notifications
You must be signed in to change notification settings - Fork 0
/
SleepSort_Spec.scala
41 lines (32 loc) · 1.12 KB
/
SleepSort_Spec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.martinbrosenberg.exercises.rosettacode
import com.martinbrosenberg.exercises.BaseSpec
import com.martinbrosenberg.exercises.rosettacode.SleepSort._
import com.martinbrosenberg.exercises.rosettacode.SleepSort_Spec._
class SleepSort_Spec extends BaseSpec {
// todo: Property testing
for (ns <- testCases) {
val expected = ns.sorted
s"SleepSort of seq $ns should be $expected" in {
var actual = Seq.empty[Any]
sort(ns, actual :+= _)
Thread.sleep(if (ns.isEmpty) 0 else (ns.max + 1) * WaitCoefficient)
assertResult(expected)(actual)
}
}
// This throws an uncaught exception, then fails because no exception was
// thrown. I have no idea how to handle that. Programmatically or emotionally.
// todo: Fix this...?
"SleepSort of seq with neg numbers should throw IllegalArgumentException" in {
pendingUntilFixed(
assertThrows[IllegalArgumentException](sort(Seq(-1)))
)
}
}
object SleepSort_Spec {
private val testCases = Seq[Seq[Int]](
Nil,
Seq(0),
Seq(1, 1), // todo: Sometimes(?) fails, generates Seq(1)
Seq(1, 3, 6, 0, 9, 7, 4, 2, 5, 8),
)
}