exercism-perl5

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

grade-school.t (2761B) - 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 GradeSchool qw<roster>;
     10 
     11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
     12 plan 8;
     13 
     14 imported_ok qw<roster> or bail_out;
     15 
     16 for my $case (@test_cases) {
     17   is roster( $case->{input}{students}, $case->{input}{desiredGrade} ),
     18     $case->{expected}, $case->{description};
     19 }
     20 
     21 __DATA__
     22 [
     23   {
     24     "description": "Roster is empty when no student is added",
     25     "expected": [],
     26     "input": {
     27       "students": []
     28     },
     29     "property": "roster"
     30   },
     31   {
     32     "description": "Student is added to the roster",
     33     "expected": [
     34       "Aimee"
     35     ],
     36     "input": {
     37       "students": [
     38         [
     39           "Aimee",
     40           2
     41         ]
     42       ]
     43     },
     44     "property": "roster"
     45   },
     46   {
     47     "description": "Multiple students in the same grade are added to the roster",
     48     "expected": [
     49       "Blair",
     50       "James",
     51       "Paul"
     52     ],
     53     "input": {
     54       "students": [
     55         [
     56           "Blair",
     57           2
     58         ],
     59         [
     60           "James",
     61           2
     62         ],
     63         [
     64           "Paul",
     65           2
     66         ]
     67       ]
     68     },
     69     "property": "roster"
     70   },
     71   {
     72     "description": "Students in multiple grades are added to the roster",
     73     "expected": [
     74       "Chelsea",
     75       "Logan"
     76     ],
     77     "input": {
     78       "students": [
     79         [
     80           "Chelsea",
     81           3
     82         ],
     83         [
     84           "Logan",
     85           7
     86         ]
     87       ]
     88     },
     89     "property": "roster"
     90   },
     91   {
     92     "description": "Students are sorted by grades and then by name in the roster",
     93     "expected": [
     94       "Anna",
     95       "Barb",
     96       "Charlie",
     97       "Alex",
     98       "Peter",
     99       "Zoe",
    100       "Jim"
    101     ],
    102     "input": {
    103       "students": [
    104         [
    105           "Peter",
    106           2
    107         ],
    108         [
    109           "Anna",
    110           1
    111         ],
    112         [
    113           "Barb",
    114           1
    115         ],
    116         [
    117           "Zoe",
    118           2
    119         ],
    120         [
    121           "Alex",
    122           2
    123         ],
    124         [
    125           "Jim",
    126           3
    127         ],
    128         [
    129           "Charlie",
    130           1
    131         ]
    132       ]
    133     },
    134     "property": "roster"
    135   },
    136   {
    137     "description": "Grade is empty if no students in the roster",
    138     "expected": [],
    139     "input": {
    140       "desiredGrade": 1,
    141       "students": []
    142     },
    143     "property": "grade"
    144   },
    145   {
    146     "description": "Students are sorted by name in a grade",
    147     "expected": [
    148       "Bradley",
    149       "Franklin"
    150     ],
    151     "input": {
    152       "desiredGrade": 5,
    153       "students": [
    154         [
    155           "Franklin",
    156           5
    157         ],
    158         [
    159           "Bradley",
    160           5
    161         ],
    162         [
    163           "Jeff",
    164           1
    165         ]
    166       ]
    167     },
    168     "property": "grade"
    169   }
    170 ]