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);
26 my @posts = map { IronMunger::Post->new(at => $_->days->ago) } @$case;
27 foreach my $test (sort keys %$expect) {
28 named_eq($name, $test, $expect->{$test}, @posts);
32 sub expect (%expect) {
34 successful_sequential_posts => $expect{sequential},
35 days_remaining_to_post => $expect{remaining},
45 case two_posts_too_far_apart =>
51 case five_posts_ok_last_needed =>
52 [ 4, 11, 18, 25, 32 ],
57 case five_posts_ok_aperture_needed =>
58 [ 4, 11, 18, 28, 32 ],
63 case five_posts_gap =>
64 [ 4, 11, 23, 25, 32 ],
69 case five_posts_aperture =>
70 [ 1, 11, 21, 31, 41 ],
75 case five_posts_aperture_2 =>
76 [ 4, 14, 24, 34, 44 ],
81 case five_posts_aperture_2 =>
82 [ 4, 13, 22, 31, 40 ],