exercism-perl5

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

sieve.t (3043B) - 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 Sieve qw<find_primes>;
     10 
     11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
     12 
     13 imported_ok qw<find_primes> or bail_out;
     14 
     15 for my $case (@test_cases) {
     16   is( find_primes( $case->{input}{limit} ),
     17     $case->{expected}, $case->{description}, );
     18 }
     19 
     20 done_testing;
     21 
     22 __DATA__
     23 [
     24   {
     25     "description": "no primes under two",
     26     "expected": [],
     27     "input": {
     28       "limit": 1
     29     },
     30     "property": "primes"
     31   },
     32   {
     33     "description": "find first prime",
     34     "expected": [
     35       2
     36     ],
     37     "input": {
     38       "limit": 2
     39     },
     40     "property": "primes"
     41   },
     42   {
     43     "description": "find primes up to 10",
     44     "expected": [
     45       2,
     46       3,
     47       5,
     48       7
     49     ],
     50     "input": {
     51       "limit": 10
     52     },
     53     "property": "primes"
     54   },
     55   {
     56     "description": "limit is prime",
     57     "expected": [
     58       2,
     59       3,
     60       5,
     61       7,
     62       11,
     63       13
     64     ],
     65     "input": {
     66       "limit": 13
     67     },
     68     "property": "primes"
     69   },
     70   {
     71     "description": "find primes up to 1000",
     72     "expected": [
     73       2,
     74       3,
     75       5,
     76       7,
     77       11,
     78       13,
     79       17,
     80       19,
     81       23,
     82       29,
     83       31,
     84       37,
     85       41,
     86       43,
     87       47,
     88       53,
     89       59,
     90       61,
     91       67,
     92       71,
     93       73,
     94       79,
     95       83,
     96       89,
     97       97,
     98       101,
     99       103,
    100       107,
    101       109,
    102       113,
    103       127,
    104       131,
    105       137,
    106       139,
    107       149,
    108       151,
    109       157,
    110       163,
    111       167,
    112       173,
    113       179,
    114       181,
    115       191,
    116       193,
    117       197,
    118       199,
    119       211,
    120       223,
    121       227,
    122       229,
    123       233,
    124       239,
    125       241,
    126       251,
    127       257,
    128       263,
    129       269,
    130       271,
    131       277,
    132       281,
    133       283,
    134       293,
    135       307,
    136       311,
    137       313,
    138       317,
    139       331,
    140       337,
    141       347,
    142       349,
    143       353,
    144       359,
    145       367,
    146       373,
    147       379,
    148       383,
    149       389,
    150       397,
    151       401,
    152       409,
    153       419,
    154       421,
    155       431,
    156       433,
    157       439,
    158       443,
    159       449,
    160       457,
    161       461,
    162       463,
    163       467,
    164       479,
    165       487,
    166       491,
    167       499,
    168       503,
    169       509,
    170       521,
    171       523,
    172       541,
    173       547,
    174       557,
    175       563,
    176       569,
    177       571,
    178       577,
    179       587,
    180       593,
    181       599,
    182       601,
    183       607,
    184       613,
    185       617,
    186       619,
    187       631,
    188       641,
    189       643,
    190       647,
    191       653,
    192       659,
    193       661,
    194       673,
    195       677,
    196       683,
    197       691,
    198       701,
    199       709,
    200       719,
    201       727,
    202       733,
    203       739,
    204       743,
    205       751,
    206       757,
    207       761,
    208       769,
    209       773,
    210       787,
    211       797,
    212       809,
    213       811,
    214       821,
    215       823,
    216       827,
    217       829,
    218       839,
    219       853,
    220       857,
    221       859,
    222       863,
    223       877,
    224       881,
    225       883,
    226       887,
    227       907,
    228       911,
    229       919,
    230       929,
    231       937,
    232       941,
    233       947,
    234       953,
    235       967,
    236       971,
    237       977,
    238       983,
    239       991,
    240       997
    241     ],
    242     "input": {
    243       "limit": 1000
    244     },
    245     "property": "primes"
    246   }
    247 ]