How to have a single test spec for many different implementations (in git)

I’m running Scala workshops regularly in Warsaw, Poland and for the exact purpose I’m developing the scalania project.

The past workshops have been quite successful with around 15 attendees every session. They clone the git repo from GitHub and solve the programming assignments on their own. It’s going tremendously well.

There’s however an issue how to collect the many implementations people are developing during the sessions under the git repository and have them all be verified by a single spec so there’s no need to change it when a new implementation shows up.

Let’s put the issue in a context.

I’ve got a single test spec, say euler.P01Spec.

package pl.japila.scalania.euler

import org.specs2.mutable
import Euler_P01.findSumOfMultiplies

class P01Spec extends mutable.Specification {
  "P01 solution" should {
    "Find the sum of all the multiples of 3 or 5 below 1000." in {
      findSumOfMultiplies(3, 5, 1000) == 233168
    }
  }
}

The spec verifies Euler_P01.findSumOfMultiplies method’s correctness.

package pl.japila.scalania.euler

object Euler_P01 {
  def findSumOfMultiplies(a: Int = 3, b: Int = 5, limit: Int = 1000): Int = ???
}

To provide an implementation of the findSumOfMultiplies method is the programming assignment. When you run the spec it fails because of the missing implementation (the ??? method throws scala.NotImplementedError). Once an implementation’s done, it’d be quite useful to push it to the repository.

The project’s under git (on GitHub as the scalania project).

Here goes the question – how to keep the many solutions/implementations from people in the git repository without the euler.P01Spec be changed when a new implementation shows up (once a pull request gets committed to the repo)?

Be Sociable, Share!
This entry was posted in Languages.

2 Responses to How to have a single test spec for many different implementations (in git)

  1. put functions in list and run this list in the spec Unit => Int

    () => {/* code here */},
    () => {/* other solution*/}

Leave a Reply

%d bloggers like this: