Last active
December 15, 2015 14:09
-
-
Save koleksiuk/5272016 to your computer and use it in GitHub Desktop.
Scala: Run & Startup with SBT + Intellij IDEA 12
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
package scala.euler | |
/* | |
* Task: http://projecteuler.net/problem=1 | |
* Description: Find the sum of all the multiples of 3 or 5 below 1000. | |
*/ | |
class ArrayFilter(n: Int) { | |
val preparedArray = Array.range(1, n) | |
// Public | |
def sum : Int = { | |
return this.filterArray.sum | |
} | |
private def filterArray : Array[Int] = { | |
return this.preparedArray.filter(x => (x % 3 == 0 || x % 5 == 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
package scala.euler | |
import org.scalatest.FunSpec | |
import org.scalatest.BeforeAndAfter | |
class ArrayFilterTest extends FunSpec with BeforeAndAfter { | |
var arrFilter: ArrayFilter = _ | |
describe("ArrayFilter") { | |
before { | |
arrFilter = new ArrayFilter(10) | |
} | |
it("should create an array") { | |
assert(arrFilter.preparedArray === Array.range(1,10)) | |
} | |
it("should return sum of filtered elements") { | |
assert(arrFilter.sum === 23) | |
} | |
} | |
describe("Euler task") { | |
it("should return correct value") { | |
arrFilter = new ArrayFilter(1000) | |
assert(arrFilter.sum === 233168) | |
} | |
} | |
} |
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
name := "Project Euler" | |
version := "0.1" | |
scalaVersion := "2.10.0" | |
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test" |
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
package scala.euler | |
object Main { | |
def main(args: Array[String]) { | |
} | |
} |
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
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" | |
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.3.0-SNAPSHOT") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment