-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateArraySpec.scala
More file actions
49 lines (42 loc) · 1.47 KB
/
RotateArraySpec.scala
File metadata and controls
49 lines (42 loc) · 1.47 KB
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
42
43
44
45
46
47
48
49
package algorithms.array
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import algorithms.array.RotateArray._
import org.scalatest.{FlatSpec, Matchers}
class RotateArraySpec extends FlatSpec with Matchers {
it should "rotate array elements" in {
//when & then
rotate(Array[Int](), 1) shouldBe Nil
rotate(Array(1), 1) shouldBe List(1)
rotate(Array(1, 2), 0) shouldBe List(1, 2)
rotate(Array(1, 2), 1) shouldBe List(2, 1)
rotate(Array(1, 2), 2) shouldBe List(1, 2)
rotate(Array(1, 2), 3) shouldBe List(2, 1)
rotate(Array(1, 2), 4) shouldBe List(1, 2)
rotate(Array(1, 2, 3, 4, 5), 0) shouldBe List(1, 2, 3, 4, 5)
rotate(Array(1, 2, 3, 4, 5), 1) shouldBe List(2, 3, 4, 5, 1)
rotate(Array(1, 2, 3, 4, 5), 2) shouldBe List(3, 4, 5, 1, 2)
rotate(Array(1, 2, 3, 4, 5), 3) shouldBe List(4, 5, 1, 2, 3)
rotate(Array(1, 2, 3, 4, 5), 4) shouldBe List(5, 1, 2, 3, 4)
rotate(Array(1, 2, 3, 4, 5), 5) shouldBe List(1, 2, 3, 4, 5)
rotate(Array(1, 2, 3, 4, 5), 6) shouldBe List(2, 3, 4, 5, 1)
}
it should "execute example test cases" in {
//given
val in = new ByteArrayInputStream(
"""2
|5 2
|1 2 3 4 5
|10 3
|2 4 6 8 10 12 14 16 18 20
|""".stripMargin.getBytes
)
val out = new ByteArrayOutputStream()
//when
RotateArray.run(in, out)
//then
out.toString shouldBe
"""3 4 5 1 2
|8 10 12 14 16 18 20 2 4 6
|""".stripMargin
}
}