From: Matt S Trout Date: Wed, 13 May 2009 15:00:37 +0000 (-0400) Subject: first sketch at calculation test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c91c4ca1c06444030d5f982dc1dea1bbddfd801d;p=engit%2FIron-Munger.git first sketch at calculation test --- diff --git a/t/calculate.t b/t/calculate.t new file mode 100644 index 0000000..0726322 --- /dev/null +++ b/t/calculate.t @@ -0,0 +1,47 @@ +use strict; +use warnings; +use Test::More qw(no_plan); + +use autobox::DateTime::Duration; +use signatures; + +BEGIN { + use_ok 'IronMunger::Post'; + use_ok 'IronMunger::Calculate'; +} + +sub named_eq ($test_name, $sub_name, $expected, @posts) { + my $sub_ref = IronMunger::Calculate->can($sub_name); + my $sub_description = join(' ', split '_', $sub_name); + cmp_ok( + $sub_ref->(@posts), '==', $expected, + "${test_name}: ${expected} ${sub_description}", + ); +} + +sub case ($name_spec, $case, $expect) { + my $name = join(' ', map ucfirst, split '_', $name_spec); + my @posts = map { IronMunger::Post->new(at => $_) } @$case; + foreach my $test (sort keys %$expect) { + named_eq($name, $test, $expect->{$test}, @posts); + } +} + +sub expect (%expect) { + +{ + successful_sequential_posts => $expect{sequential}, + days_remaining_to_post => $expect{remaining}, + }; +} + +case two_posts_ok => + [ 5->days->ago, 13->days->ago ], + expect + sequential => 2, + remaining => 5; + +case two_posts_too_far_apart => + [ 5->days->ago, 20->days->ago ], + expect + sequential => 1, + remaining => 5;