Skip to content

Instantly share code, notes, and snippets.

@koleksiuk
Last active December 15, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koleksiuk/5272016 to your computer and use it in GitHub Desktop.
Save koleksiuk/5272016 to your computer and use it in GitHub Desktop.
Scala: Run & Startup with SBT + Intellij IDEA 12
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))
}
}
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)
}
}
}
name := "Project Euler"
version := "0.1"
scalaVersion := "2.10.0"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
package scala.euler
object Main {
def main(args: Array[String]) {
}
}
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