Brief but scalable Scala / sbt testing to verify Project Euler responses

Im using Project Euler to learn functional programming in Scala, as well as sbt and other best practices. My initial kick in creating tests to test solutions using ScalaTest was:

package euler
import org.scalatest._

class SolutionsSpec extends Spec with Matchers {
    "The problems" should "have the correct solutions" in {
        Problem1.solve should be (  233168 )
        Problem2.solve should be ( 4613732 )
        Problem3.solve should be (    6857 )
        Problem4.solve should be (  906609 )
    }
}

This is concise, but I'm afraid it may not scale if I ever run into more difficult problems with longer lead times. As far as I can tell, I cannot verify individual problems in this way.

I searched on GitHub and found two useful examples similar to what I'm trying to do:

, , Im .

: , - , ?

: , TDD Project Euler. , . , .

2: FunSuite:

class SolutionsSuite extends FunSuite with Matchers {
    test("Problem 1") { Problem1.solve should be (  233168 ) }
    test("Problem 2") { Problem2.solve should be ( 4613732 ) }
    test("Problem 3") { Problem3.solve should be (    6857 ) }
    test("Problem 4") { Problem4.solve should be (  906609 ) }
}

, . :

$ sbt test
...
[info] SolutionsSuite:
[info] - Problem 1 (28 milliseconds)
[info] - Problem 2 (4 milliseconds)
[info] - Problem 3 (38 milliseconds)
[info] - Problem 4 (172 milliseconds)

, . , , , , , sbt: - sbt.

3. , sbt 0.13.3 junit # 911.

4. Project Euler GitHub.

+4
1

, https://github.com/sethtisue/project-euler. :

class Problem1 extends Problem(1, "12345") {
  def solve: Int = ...
}

"12345" - ( ), solve ( .toString ed, - , ).

Problem , , sbt test-only , .

+2

Source: https://habr.com/ru/post/1531080/


All Articles