Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Last active August 29, 2015 14:02
Show Gist options
  • Save MikeMKH/f8af4e35fe798ebec4f2 to your computer and use it in GitHub Desktop.
Save MikeMKH/f8af4e35fe798ebec4f2 to your computer and use it in GitHub Desktop.
Leap year kata in Scala using ScalaTest
name := "LeapYear"
version := "1.0"
scalaVersion := "2.11.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.7" % "test"
package com.bigcompany.utils.test
import org.scalatest._
object LeapYear {
def isLeapYear(year: Int) = (year % 4, year % 100, year % 400) match {
case (_, _, 0) => true
case (_, 0, _) => false
case (0, _, _) => true
case _ => false
}
}
class LeapYearSpec extends FunSpec {
describe("Validate Leap Year calculation") {
it("should return true for year 4") {
assert(LeapYear.isLeapYear(4) == true)
}
it("should return true for year 1") {
assert(LeapYear.isLeapYear(1) == false)
}
it("should return true for year 64") {
assert(LeapYear.isLeapYear(64) == true)
}
it("should return true for year 2000") {
assert(LeapYear.isLeapYear(2000) == true)
}
it("should return true for year 1900") {
assert(LeapYear.isLeapYear(1900) == false)
}
}
}
@MikeMKH
Copy link
Author

MikeMKH commented Jun 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment