Skip to content

Commit

Permalink
Following up Issue #16. Thanks @etorreborre!
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklaskowski committed Nov 3, 2013
2 parents abad695 + 8a543d7 commit dd7b65f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package pl.japila.scalania.euler

object Euler_P01 {

val solutions = List[(Int, Int, Int) => Int](
findSumOfMultiplies,
findSumOfMultiplies_jl
findSumOfMultiplies_jl,
findSumOfMultiplies_eric
)

def findSumOfMultiplies(a: Int = 3, b: Int = 5, limit: Int = 1000): Int = ???
def findSumOfMultiplies: (Int, Int, Int) => Int = (a: Int, b: Int, limit: Int) => ???

def findSumOfMultiplies_jl: (Int, Int, Int) => Int = (a: Int, b: Int, limit: Int) => ???

def findSumOfMultiplies_eric = (a: Int, b: Int, limit: Int) =>
(0 until limit).filter(n => n % a == 0 || n % b == 0).sum

def findSumOfMultiplies_jl(a: Int = 3, b: Int = 5, limit: Int = 1000): Int = ???
}
19 changes: 15 additions & 4 deletions exercises/src/test/scala/pl/japila/scalania/euler/P01Spec.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package pl.japila.scalania.euler

import org.specs2.mutable._
import Euler_P01.solutions
import org.specs2.specification.Tables
import Euler_P01._

class P01Spec extends Specification {
class P01Spec extends Specification with Tables {
"P01 solution" should {
"Find the sum of all the multiples of 3 or 5 below 1000." in {
solutions.forall { f => f(3, 5, 1000) === 233168 }
"Find the sum of all the multiples of 3 or 5 below 1000." >> {

val titles = List("name", "function")
val dr2s = List[DataRow2[String, (Int, Int, Int) => Int]]()
val rows = solutions.foldLeft(dr2s) { (l, f) =>
DataRow2(s"${f.getClass.getSimpleName} solution", f) :: l
}

val t2 = new Table2[String, (Int, Int, Int) => Int](titles, rows.reverse)
t2.rows.foreach { row =>
row.t1 >> { row.t2(3, 5, 1000) must_== 233168 }
}; br
}
}
}

0 comments on commit dd7b65f

Please sign in to comment.