exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs | README

sum-of-multiples.t (3650B) - raw


      1 #!/usr/bin/env perl
      2 use Test2::V0;
      3 use JSON::PP;
      4 use constant JSON => JSON::PP->new;
      5 
      6 use FindBin qw<$Bin>;
      7 use lib $Bin, "$Bin/local/lib/perl5";
      8 
      9 use SumOfMultiples qw<sum_of_multiples>;
     10 
     11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
     12 
     13 imported_ok qw<sum_of_multiples> or bail_out;
     14 
     15 for my $case (@test_cases) {
     16   is( sum_of_multiples( $case->{input} ),
     17     $case->{expected}, $case->{description}, );
     18 }
     19 
     20 done_testing;
     21 
     22 __DATA__
     23 [
     24   {
     25     "description": "no multiples within limit",
     26     "expected": 0,
     27     "input": {
     28       "factors": [
     29         3,
     30         5
     31       ],
     32       "limit": 1
     33     },
     34     "property": "sum"
     35   },
     36   {
     37     "description": "one factor has multiples within limit",
     38     "expected": 3,
     39     "input": {
     40       "factors": [
     41         3,
     42         5
     43       ],
     44       "limit": 4
     45     },
     46     "property": "sum"
     47   },
     48   {
     49     "description": "more than one multiple within limit",
     50     "expected": 9,
     51     "input": {
     52       "factors": [
     53         3
     54       ],
     55       "limit": 7
     56     },
     57     "property": "sum"
     58   },
     59   {
     60     "description": "more than one factor with multiples within limit",
     61     "expected": 23,
     62     "input": {
     63       "factors": [
     64         3,
     65         5
     66       ],
     67       "limit": 10
     68     },
     69     "property": "sum"
     70   },
     71   {
     72     "description": "each multiple is only counted once",
     73     "expected": 2318,
     74     "input": {
     75       "factors": [
     76         3,
     77         5
     78       ],
     79       "limit": 100
     80     },
     81     "property": "sum"
     82   },
     83   {
     84     "description": "a much larger limit",
     85     "expected": 233168,
     86     "input": {
     87       "factors": [
     88         3,
     89         5
     90       ],
     91       "limit": 1000
     92     },
     93     "property": "sum"
     94   },
     95   {
     96     "description": "three factors",
     97     "expected": 51,
     98     "input": {
     99       "factors": [
    100         7,
    101         13,
    102         17
    103       ],
    104       "limit": 20
    105     },
    106     "property": "sum"
    107   },
    108   {
    109     "description": "factors not relatively prime",
    110     "expected": 30,
    111     "input": {
    112       "factors": [
    113         4,
    114         6
    115       ],
    116       "limit": 15
    117     },
    118     "property": "sum"
    119   },
    120   {
    121     "description": "some pairs of factors relatively prime and some not",
    122     "expected": 4419,
    123     "input": {
    124       "factors": [
    125         5,
    126         6,
    127         8
    128       ],
    129       "limit": 150
    130     },
    131     "property": "sum"
    132   },
    133   {
    134     "description": "one factor is a multiple of another",
    135     "expected": 275,
    136     "input": {
    137       "factors": [
    138         5,
    139         25
    140       ],
    141       "limit": 51
    142     },
    143     "property": "sum"
    144   },
    145   {
    146     "description": "much larger factors",
    147     "expected": 2203160,
    148     "input": {
    149       "factors": [
    150         43,
    151         47
    152       ],
    153       "limit": 10000
    154     },
    155     "property": "sum"
    156   },
    157   {
    158     "description": "all numbers are multiples of 1",
    159     "expected": 4950,
    160     "input": {
    161       "factors": [
    162         1
    163       ],
    164       "limit": 100
    165     },
    166     "property": "sum"
    167   },
    168   {
    169     "description": "no factors means an empty sum",
    170     "expected": 0,
    171     "input": {
    172       "factors": [],
    173       "limit": 10000
    174     },
    175     "property": "sum"
    176   },
    177   {
    178     "description": "the only multiple of 0 is 0",
    179     "expected": 0,
    180     "input": {
    181       "factors": [
    182         0
    183       ],
    184       "limit": 1
    185     },
    186     "property": "sum"
    187   },
    188   {
    189     "description": "the factor 0 does not affect the sum of multiples of other factors",
    190     "expected": 3,
    191     "input": {
    192       "factors": [
    193         3,
    194         0
    195       ],
    196       "limit": 4
    197     },
    198     "property": "sum"
    199   },
    200   {
    201     "description": "solutions using include-exclude must extend to cardinality greater than 3",
    202     "expected": 39614537,
    203     "input": {
    204       "factors": [
    205         2,
    206         3,
    207         5,
    208         7,
    209         11
    210       ],
    211       "limit": 10000
    212     },
    213     "property": "sum"
    214   }
    215 ]