Skip to content

Commit

Permalink
fix: Action apply for sub type class & Action test
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymax25 committed Jan 9, 2022
1 parent 6e281e7 commit d77104b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion projet/funprog-al/src/main/scala/progfun/InputLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class InputLoader(filePath: String) {
)
}
val actions: List[Action] =
l(1).split("").toList.map(s => Action.getActionFromString(s))
l(1).split("").toList.map(s => Action(s))

new Mower(
index + 1,
Expand Down
3 changes: 1 addition & 2 deletions projet/funprog-al/src/main/scala/progfun/mower/Action.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ trait Action {
}

object Action {

def getActionFromString(str: String): Action = str match {
def apply(str: String): Action = str match {
case "G" => new Left("G")
case "D" => new Right("D")
case "A" => new Advance("A")
Expand Down
18 changes: 18 additions & 0 deletions projet/funprog-al/src/test/scala/progFun/ActionSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import org.scalatest.funsuite.AnyFunSuite
import fr.esgi.al.funprog._

class ActionSpec extends AnyFunSuite {

test("Parse action") {
val actionStr = "A"
val action = Action(actionStr)

val test = action match {
case Advance(_) => true
case Right(_) => false
case Left(_) => false
}

assert(test == true)
}
}
6 changes: 3 additions & 3 deletions projet/funprog-al/src/test/scala/progFun/MowerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MowerSpec extends AnyFunSuite {
val point = new Point(x, y)
val direction = new North()
val actions: List[Action] =
"AADGA".split("").toList.map(s => Action.getActionFromString(s))
"AADGA".split("").toList.map(s => Action(s))

new Mower(
id,
Expand All @@ -22,13 +22,13 @@ class MowerSpec extends AnyFunSuite {
)
}

test("Should get a mower and verify it has an id") {
test("Mower should exist and verify it has an id") {
val mower = getTestMower()

assert(mower.id === 1)
}

test("Should advance a mower up once") {
test("Mower should advance a mower up once") {
val mower = getTestMower()

val updated = mower.advance(new Point(5, 5), Nil)
Expand Down

0 comments on commit d77104b

Please sign in to comment.