1
exercism fetch scala queen-attack

src/test/scala/QueenAttackTest.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import org.scalatest.{Matchers, FunSuite}

/** @version 1.0.0 */
class QueenAttackTest extends FunSuite with Matchers {

  private def create(x: Int, y: Int): Queen = {
    Queen.create(x, y) match {
      case Some(q) => q
      case None => fail("Error creating queen")
    }
  }

  test("queen with a valid position") {
    Queen.create(2,2) should be (Some(Queen(2,2)))
  }

  test("queen must have positive rank") {
    pending
    Queen.create(-2,2) should be (None)
  }

  test("queen must have rank on board") {
    pending
    Queen.create(8,4) should be (None)
  }

  test("queen must have positive file") {
    pending
    Queen.create(2,-2) should be (None)
  }

  test("queen must have file on board") {
    pending
    Queen.create(4,8) should be (None)
  }

  test("can not attack") {
    pending
    QueenAttack.canAttack(create(2,4), create(6,6)) should be (false)
  }

  test("can attack on same rank") {
    pending
    QueenAttack.canAttack(create(2,4), create(2,6)) should be (true)
  }

  test("can attack on same file") {
    pending
    QueenAttack.canAttack(create(4,5), create(2,5)) should be (true)
  }

  test("can attack on first diagonal") {
    pending
    QueenAttack.canAttack(create(2,2), create(0,4)) should be (true)
  }

  test("can attack on second diagonal") {
    pending
    QueenAttack.canAttack(create(2,2), create(3,1)) should be (true)
  }

  test("can attack on third diagonal") {
    pending
    QueenAttack.canAttack(create(2,2), create(1,1)) should be (true)
  }

  test("can attack on fourth diagonal") {
    pending
    QueenAttack.canAttack(create(2,2), create(5,5)) should be (true)
  }
}