3 use Test::More qw(no_plan);
6 use_ok 'IronMunger::Post';
7 use_ok 'IronMunger::Calculate';
11 use autobox::DateTime::Duration;
14 sub named_eq ($test_name, $sub_name, $expected, @posts) {
15 my $sub_ref = IronMunger::Calculate->can($sub_name);
16 die "Couldn't find $sub_name in IronMunger::Calculate" unless $sub_ref;
17 my $sub_description = join(' ', split '_', $sub_name);
19 $sub_ref->(@posts), '==', $expected,
20 "${test_name}: ${expected} ${sub_description}",
24 sub case ($name_spec, $case, $expect) {
25 my $name = join(' ', map ucfirst, split '_', $name_spec);
27 IronMunger::Post->new(url => 'http://localhost', at => $_->days->ago)
29 foreach my $test (sort keys %$expect) {
30 named_eq($name, $test, $expect->{$test}, @posts);
34 sub expect (%expect) {
36 successful_sequential_posts => $expect{sequential},
37 days_remaining_to_post => $expect{remaining},
47 case two_posts_too_far_apart =>
53 case five_posts_ok_last_needed =>
54 [ 4, 11, 18, 25, 32 ],
59 case five_posts_ok_aperture_needed =>
60 [ 4, 11, 18, 28, 32 ],
65 case five_posts_gap =>
66 [ 4, 11, 23, 25, 32 ],
71 case five_posts_aperture =>
72 [ 1, 11, 21, 31, 41 ],
77 case five_posts_aperture_2 =>
78 [ 4, 14, 24, 34, 44 ],
83 case five_posts_aperture_2 =>
84 [ 4, 13, 22, 31, 40 ],