Skip to content
Snippets Groups Projects
Commit df73de93 authored by Viktor Kuncak's avatar Viktor Kuncak
Browse files

Improved the date conversion benchmark

parent 4bad9728
No related branches found
No related tags found
No related merge requests found
...@@ -7,20 +7,24 @@ import leon.lang.synthesis._ ...@@ -7,20 +7,24 @@ import leon.lang.synthesis._
*/ */
object ZuneBug { object ZuneBug {
@inline
def leapsTill(year: BigInt): BigInt = { def leapsTill(year: BigInt): BigInt = {
require(year >= 0) require(year >= 0)
val y1 = year - 1 val y1 = year - 1
y1/4 + y1/100 + y1/400 y1/4 + y1/100 + y1/400
} }
@inline
def isLeap(year: BigInt): Boolean = { def isLeap(year: BigInt): Boolean = {
require(year >= 0) require(year >= 0)
leapsTill(year+1) > leapsTill(year) leapsTill(year+1) > leapsTill(year)
} }
def yearDay(daysSince1980: BigInt): (BigInt, BigInt) = { // wrong, accidentaly underspecified
def yearDayConfused(daysSince1980: BigInt): (BigInt, BigInt) = {
require(daysSince1980 >= 0) require(daysSince1980 >= 0)
???[(BigInt,BigInt)] ???[(BigInt,BigInt)]
} ensuring (res => { } ensuring (res => {
val (year, day) = res val (year, day) = res
year >= 1980 && year >= 1980 &&
0 <= day && day <= 366 && 0 <= day && day <= 366 &&
...@@ -28,4 +32,27 @@ object ZuneBug { ...@@ -28,4 +32,27 @@ object ZuneBug {
daysSince1980 == (year - 1980)*365 + daysSince1980 == (year - 1980)*365 +
leapsTill(year) - leapsTill(1980) + day leapsTill(year) - leapsTill(1980) + day
}) })
// should be correct
def yearDay(daysSince1980: BigInt): (BigInt, BigInt) = {
require(daysSince1980 >= 0)
???[(BigInt,BigInt)]
} ensuring (res => {
val (year, day) = res
year >= 1980 &&
0 <= day && day <= 365 &&
(day == 365 ==> isLeap(year)) &&
daysSince1980 == (year - 1980)*365 +
leapsTill(year) - leapsTill(1980) + day
})
// test run-time constraint solving. smt-cvc4 seems fastest
def testYearDay = {
(yearDay(364),
yearDay(365),
yearDay(366),
yearDay(366+364),
yearDay(366+365))
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment