Skip to content

Commit

Permalink
Queens - use object instead of an instance - refs exercism#242. Add Q…
Browse files Browse the repository at this point in the history
…ueens.scala - refs exercism#137. Add topics to config.json - refs exercism#125
  • Loading branch information
ricemery committed Dec 15, 2016
1 parent 29079be commit aa7dfd3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@
"slug": "queen-attack",
"difficulty": 1,
"topics": [
"Strings",
"Optional values",
"Logic",
"Games"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion exercises/queen-attack/example.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
case class Queens() {
object Queens {

def boardString(white: Option[Position], black: Option[Position]): String = {

Expand Down Expand Up @@ -34,3 +34,4 @@ case class Queens() {
}

case class Position(x: Int, y: Int)

8 changes: 8 additions & 0 deletions exercises/queen-attack/src/main/scala/Queens.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Queens {

def boardString(white: Option[Position], black: Option[Position]): String = ???

def canAttack(white: Position, black: Position): Boolean = ???
}

case class Position(x: Int, y: Int)
18 changes: 9 additions & 9 deletions exercises/queen-attack/src/test/scala/QueensTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.scalatest.{Matchers, FunSuite}

class QueensTest extends FunSuite with Matchers {
test ("empty boardString") {
Queens().boardString(None, None) should equal(
Queens.boardString(None, None) should equal(
"_ _ _ _ _ _ _ _\n" +
"_ _ _ _ _ _ _ _\n" +
"_ _ _ _ _ _ _ _\n" +
Expand All @@ -15,7 +15,7 @@ class QueensTest extends FunSuite with Matchers {

test("boardString") {
pending
Queens().boardString(Some(Position(2, 4)), Some(Position(6, 6))) should equal(
Queens.boardString(Some(Position(2, 4)), Some(Position(6, 6))) should equal(
"_ _ _ _ _ _ _ _\n" +
"_ _ _ _ _ _ _ _\n" +
"_ _ _ _ W _ _ _\n" +
Expand All @@ -28,24 +28,24 @@ class QueensTest extends FunSuite with Matchers {

test("canAttack - false") {
pending
Queens().canAttack(Position(2, 3), Position(4, 7)) should be (false)
Queens.canAttack(Position(2, 3), Position(4, 7)) should be (false)
}

test("canAttack - vert attack") {
pending
Queens().canAttack(Position(2, 4), Position(2, 7)) should be (true)
Queens.canAttack(Position(2, 4), Position(2, 7)) should be (true)
}

test("canAttack - horiz attack") {
pending
Queens().canAttack(Position(5, 4), Position(2, 4)) should be (true)
Queens.canAttack(Position(5, 4), Position(2, 4)) should be (true)
}

test("canAttack - diag attack") {
pending
Queens().canAttack(Position(1, 1), Position(6, 6)) should be (true)
Queens().canAttack(Position(0, 6), Position(1, 7)) should be (true)
Queens().canAttack(Position(4, 1), Position(6, 3)) should be (true)
Queens().canAttack(Position(2, 2), Position(1, 3)) should be (true)
Queens.canAttack(Position(1, 1), Position(6, 6)) should be (true)
Queens.canAttack(Position(0, 6), Position(1, 7)) should be (true)
Queens.canAttack(Position(4, 1), Position(6, 3)) should be (true)
Queens.canAttack(Position(2, 2), Position(1, 3)) should be (true)
}
}

0 comments on commit aa7dfd3

Please sign in to comment.