Last active
August 29, 2015 14:02
-
-
Save MikeMKH/f8af4e35fe798ebec4f2 to your computer and use it in GitHub Desktop.
Leap year kata in Scala using ScalaTest
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
name := "LeapYear" | |
version := "1.0" | |
scalaVersion := "2.11.1" | |
libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.7" % "test" |
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
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my blog post which goes with this: http://comp-phil.blogspot.com/2014/06/leap-year-in-key-of-c-f-haskell-and.html