-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnightWalkSpec.scala
47 lines (39 loc) · 960 Bytes
/
KnightWalkSpec.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
42
43
44
45
46
47
package algorithms.graph.bfs
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import java.util
import KnightWalk._
import org.scalatest.{FlatSpec, Matchers}
import scala.collection.JavaConverters._
class KnightWalkSpec extends FlatSpec with Matchers {
it should "find all targets from then given point" in {
//when & then
targets(new util.HashSet[Point](), 4, 7, new Point(2, 6)).asScala shouldBe Set(
new Point(4, 7),
new Point(4, 5),
new Point(3, 4),
new Point(1, 4)
)
}
it should "execute example test cases" in {
//given
val in = new ByteArrayInputStream(
"""3
|4 7
|2 6 2 4
|4 7
|2 6 3 4
|7 13
|2 8 3 4
|""".stripMargin.getBytes
)
val out = new ByteArrayOutputStream()
//when
KnightWalk.run(in, out)
//then
out.toString shouldBe
"""2
|1
|3
|""".stripMargin
}
}