From: Matt S Trout Date: Sat, 16 May 2009 20:17:10 +0000 (+0100) Subject: level calculation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=69941ee3552e918352c66954208ad46a914287ca;p=engit%2FIron-Munger.git level calculation --- diff --git a/lib/IronMunger/Calculate.pm b/lib/IronMunger/Calculate.pm index ab01eca..43b7fe0 100644 --- a/lib/IronMunger/Calculate.pm +++ b/lib/IronMunger/Calculate.pm @@ -9,7 +9,7 @@ use signatures; use Sub::Exporter -setup => { exports => [ - qw(successful_sequential_posts days_remaining_to_post) + qw(successful_sequential_posts days_remaining_to_post level_for_post_count) ] }; @@ -64,4 +64,11 @@ sub days_remaining_to_post (@posts) { return check_both(\&check_time_remaining, @posts); } +sub level_for_post_count($count) { + return 'paper' if $count < 4; + return 'stone' if $count < 12; + return 'bronze' if $count < 36; + return 'iron'; +} + 1; diff --git a/t/calculate_level.t b/t/calculate_level.t new file mode 100644 index 0000000..0c01b3a --- /dev/null +++ b/t/calculate_level.t @@ -0,0 +1,23 @@ +use strict; +use warnings; +use Test::More qw(no_plan); + +BEGIN { + use_ok 'IronMunger::Calculate', 'level_for_post_count'; +} + +my @spec = qw( + 0 paper + 3 paper + 4 stone + 11 stone + 12 bronze + 35 bronze + 36 iron + 50 iron +); + +while (@spec > 2) { + my ($count, $level) = (shift(@spec),shift(@spec)); + is(level_for_post_count($count), $level, "${count} posts means ${level} man"); +}