This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(_)) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |