Created
October 30, 2013 08:07
-
-
Save eirikm/7228787 to your computer and use it in GitHub Desktop.
Bonusoppgave for extractors
This file contains 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 scalakurs.patternmatching | |
import org.scalatest.FunSpec | |
import org.scalatest.matchers.ShouldMatchers | |
class DateExtractorsTest extends FunSpec with ShouldMatchers { | |
describe("IsoDate unapply") { | |
it("\"2013-10-29\" should return Some((2013, 10, 29))") { | |
"2013-10-29" match { | |
case IsoDate(year, month, date) => | |
case _ => fail | |
} | |
} | |
it("\"2013-10-30\" should return Some((2013, 10, 30))") { | |
"2013-10-30" match { | |
case IsoDate(year, month, date) => | |
case _ => fail | |
} | |
} | |
it("\"notADate\" should return None") { | |
IsoDate.unapply("ikkeEnDato") should be (None) | |
} | |
it("\"2013-oct-29\" should return None (month not an int)") { | |
IsoDate.unapply("2013-oct-29") should be (None) | |
} | |
it("\"2013-0-10\" should return None (month less than 1)") { | |
IsoDate.unapply("2013-0-10") should be (None) | |
} | |
it("\"2013-20-10\" should return None (month larger than 12)") { | |
IsoDate.unapply("2013-20-10") should be (None) | |
} | |
it("\"2013-10-0\" should return None (date less than 1)") { | |
IsoDate.unapply("2013-10-40") should be (None) | |
} | |
it("\"2013-10-40\" should return None (date larger than 31)") { | |
IsoDate.unapply("2013-10-40") should be (None) | |
} | |
it("\"2013-02-30\" should return None (illegal date)") { | |
IsoDate.unapply("2013-02-30") should be (None) | |
} | |
} | |
} | |
object IsoDate { | |
def unapply(str: String): Option[(Int, Int, Int)] = ??? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment