Skip to content

Queens - use object instead of an instance - refs #242. Add Queens.sc… #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}