level calculation
Matt S Trout [Sat, 16 May 2009 20:17:10 +0000 (21:17 +0100)]
lib/IronMunger/Calculate.pm
t/calculate_level.t [new file with mode: 0644]

index ab01eca..43b7fe0 100644 (file)
@@ -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 (file)
index 0000000..0c01b3a
--- /dev/null
@@ -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");
+}