Skip to content

Instantly share code, notes, and snippets.

View sanjivsahayamrea's full-sized avatar

sanjivsahayamrea

View GitHub Profile
import org.specs2.mutable.Specification
import org.specs2.specification.core.Fragments
final class TabulatedSpec extends Specification {
def mult(value1: Int, value2: Int): Int = value1 * value2
"Tabulated functions" should {
def findWinner(candidates: Seq[String], rotations: Int): Option[String] = {
if (candidates.isEmpty || rotations <= 0) None
else {
val numCandidates = candidates.length
val randomIndexes = List.fill(rotations)(scala.util.Random.nextInt(numCandidates))
val meanOp = randomIndexes.drop(rotations / 2).headOption
meanOp.map(candidates(_))
}
}
final case class Person(name: String, age: Int)
final class EmptyNameException(message: String) extends Exception(message)
final class InvalidAgeException(message: String) extends Exception(message)
// with Exceptions
def getName(providedName: String) : String = {
if (providedName.trim.isEmpty) throw new EmptyNameException(s"provided name is empty")
else providedName.trim
}