update .gitignore to not skip testing CSV files and add them
[engit/Iron-Munger.git] / t / calculate.t
CommitLineData
c91c4ca1 1use strict;
2use warnings;
3use Test::More qw(no_plan);
4
c91c4ca1 5BEGIN {
6 use_ok 'IronMunger::Post';
7 use_ok 'IronMunger::Calculate';
8}
9
38827ef4 10use autobox;
11use autobox::DateTime::Duration;
12use signatures;
13
c91c4ca1 14sub named_eq ($test_name, $sub_name, $expected, @posts) {
15 my $sub_ref = IronMunger::Calculate->can($sub_name);
38827ef4 16 die "Couldn't find $sub_name in IronMunger::Calculate" unless $sub_ref;
c91c4ca1 17 my $sub_description = join(' ', split '_', $sub_name);
18 cmp_ok(
19 $sub_ref->(@posts), '==', $expected,
20 "${test_name}: ${expected} ${sub_description}",
21 );
22}
23
24sub case ($name_spec, $case, $expect) {
25 my $name = join(' ', map ucfirst, split '_', $name_spec);
1dc0a45b 26 my @posts = map { IronMunger::Post->new(at => $_->days->ago) } @$case;
c91c4ca1 27 foreach my $test (sort keys %$expect) {
28 named_eq($name, $test, $expect->{$test}, @posts);
29 }
30}
31
32sub expect (%expect) {
33 +{
34 successful_sequential_posts => $expect{sequential},
35 days_remaining_to_post => $expect{remaining},
36 };
37}
38
39case two_posts_ok =>
1dc0a45b 40 [ 5, 13 ],
c91c4ca1 41 expect
42 sequential => 2,
43 remaining => 5;
44
45case two_posts_too_far_apart =>
1dc0a45b 46 [ 5, 20 ],
c91c4ca1 47 expect
48 sequential => 1,
49 remaining => 5;
f9c2ac83 50
51case five_posts_ok_last_needed =>
52 [ 4, 11, 18, 25, 32 ],
53 expect
54 sequential => 5,
55 remaining => 6;
56
57case five_posts_ok_aperture_needed =>
58 [ 4, 11, 18, 28, 32 ],
59 expect
60 sequential => 5,
61 remaining => 4;
e1738c74 62
63case five_posts_gap =>
64 [ 4, 11, 23, 25, 32 ],
65 expect
66 sequential => 2,
67 remaining => 6;
68
69case five_posts_aperture =>
70 [ 1, 11, 21, 31, 41 ],
71 expect
72 sequential => 4,
73 remaining => 1;
74
75case five_posts_aperture_2 =>
76 [ 4, 14, 24, 34, 44 ],
77 expect
78 sequential => 3,
79 remaining => 6;
80
81case five_posts_aperture_2 =>
82 [ 4, 13, 22, 31, 40 ],
83 expect
84 sequential => 4,
85 remaining => 1;