Skip to content

Commit

Permalink
Reading from file, eclipse plugin, test
Browse files Browse the repository at this point in the history
Some basic infrastructure stuff for demoing.
  • Loading branch information
jyrkiput committed Mar 25, 2012
1 parent d6e1c4f commit 256be4a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
2 changes: 2 additions & 0 deletions project/plugins.sbt
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")
57 changes: 53 additions & 4 deletions src/main/scala/org/agilefinland/gameoflife/Main.scala
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)


}
10 changes: 10 additions & 0 deletions src/test/scala/org/agilefinland/gameoflife/MainTest.scala
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
}
}

0 comments on commit 256be4a

Please sign in to comment.