-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reading from file, eclipse plugin, test
Some basic infrastructure stuff for demoing.
- Loading branch information
Showing
3 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/" | ||
|
||
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0") | ||
|
||
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,59 @@ | ||
package org.agilefinland.gameoflife | ||
|
||
class Main { | ||
def foo() : Int = { | ||
0 | ||
import io.Source | ||
import collection.mutable.ListBuffer | ||
|
||
sealed abstract case class Cell(alive: Boolean) | ||
case class Dead() extends Cell(true) | ||
case class Alive() extends Cell(false) | ||
|
||
case class Board(listOfCells: List[Cell], size : Coordinate) | ||
|
||
class Coordinate(val x: Int, val y: Int) { | ||
|
||
override def toString = "x: " + x.toString + ", y: " + y.toString | ||
|
||
} | ||
|
||
object Coordinate { | ||
def apply(x : Int, y: Int) = new Coordinate(x,y) | ||
def apply(s: String): Coordinate = { | ||
val parts = s split " " | ||
if(parts.length == 2) Coordinate(parts(0).toInt, parts(1).toInt) | ||
throw new IllegalArgumentException | ||
} | ||
|
||
def unapply(string : String): Option[(Int, Int)] = { | ||
val parts = string split " " | ||
if(parts.length == 2) (Some(parts(0).toInt, parts(1).toInt)) else None | ||
} | ||
|
||
def unapply(x: Int, y: Int): Option[(Int, Int)] = { | ||
Some(x, y) | ||
} | ||
} | ||
|
||
class Main { | ||
val foo = 0 | ||
} | ||
|
||
object Main extends App { | ||
println("Hello World!") | ||
val file = Source.fromFile("test.txt") | ||
val lines = file.getLines.toList | ||
file.close(); | ||
val firstLine = lines(0) | ||
|
||
val size : Coordinate = firstLine match { | ||
case Coordinate(x,y) => Coordinate(x, y) | ||
case _ => throw new IllegalArgumentException("Size was not defined") | ||
} | ||
|
||
val list = for(val line <- lines drop 1; val c <- line.toCharArray ) yield c match { | ||
case '.' => new Dead() | ||
case '*' => new Alive() | ||
} | ||
|
||
val b = new Board(list, size) | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.agilefinland.gameoflife | ||
|
||
import org.scalatest.FunSuite | ||
|
||
class MainTest extends FunSuite { | ||
test("Main class") { | ||
val m = new Main | ||
m.foo === 0 | ||
} | ||
} |