]> git.madduck.net Git - etc/awesome.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

luatz/timetable: Optimize and export `is_leap`; add tests
authordaurnimator <quae@daurnimator.com>
Fri, 29 Aug 2014 18:56:13 +0000 (14:56 -0400)
committerdaurnimator <quae@daurnimator.com>
Fri, 29 Aug 2014 19:22:05 +0000 (15:22 -0400)
luatz/timetable.lua
spec/timetable_spec.lua

index f09637255e7676bc821342dca9e91e0b4ba25e59..99ac52ee8d238f85e350e5e4ed2a92b1fa6b32b6 100644 (file)
@@ -16,7 +16,13 @@ end
 local sakamoto = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
 
 local function is_leap ( y )
-       return (y % 4) == 0 and (y % 100) ~= 0 or (y % 400) == 0
+       if (y % 4) ~= 0 then
+               return false
+       elseif (y % 100) ~= 0 then
+               return true
+       else
+               return (y % 400) == 0
+       end
 end
 
 local function year_length ( y )
@@ -200,6 +206,7 @@ local function new_from_timestamp ( ts )
 end
 
 return {
+       is_leap = is_leap ;
        day_of_year = day_of_year ;
        day_of_week = day_of_week ;
        normalise = normalise ;
index b76991159cd775c083698c8e81a72c8e1323a753..0ff42b12d7bbccb894a2f0143481dcb10278afc9 100644 (file)
@@ -9,6 +9,19 @@ describe ( "Timetable library" , function ( )
                })
        end
 
+       it ( "#is_leap is correct" , function ( )
+               assert.same ( false , timetable.is_leap ( 1 ) )
+               assert.same ( false , timetable.is_leap ( 3 ) )
+               assert.same ( true  , timetable.is_leap ( 4 ) )
+               assert.same ( true  , timetable.is_leap ( 2000 ) )
+               assert.same ( true  , timetable.is_leap ( 2004 ) )
+               assert.same ( true  , timetable.is_leap ( 2012 ) )
+               assert.same ( false , timetable.is_leap ( 2013 ) )
+               assert.same ( false , timetable.is_leap ( 2014 ) )
+               assert.same ( false , timetable.is_leap ( 2100 ) )
+               assert.same ( true  , timetable.is_leap ( 2400 ) )
+       end )
+
        it ( "#normalise gets #wday (day of week) correct" , function ( )
 
                local function assert_same_wday ( year , month , day )