Sha256: 5bac7e1265125fdc8239de3045e65d2e91a35be56b92bf782fbaabab0d0da0c6

Contents?: true

Size: 1.71 KB

Versions: 83

Compression:

Stored size: 1.71 KB

Contents

exercise: GradeSchool
version: 3
plan: 18
tests: |-
  subtest "Roster class methods", {
    plan 3;
    ok ::('Roster').can($_), $_ for <add-student list-grade list-all>;
  }

  my $roster = ::('Roster').new;

  ok $roster.?add-student(:name('Jim'), :2grade), 'Add Jim to grade 2';
  cmp-ok $roster.?list-grade(2), '~~', <Jim>, 'List grade 2';

  ok $roster.?add-student(:name('Zoe'), :2grade), 'Add Zoe to grade 2';
  ok $roster.?add-student(:name('Barb'), :1grade), 'Add Barb to grade 1';
  cmp-ok $roster.?list-grade(2), '~~', <Jim Zoe>, 'List grade 2';
  cmp-ok $roster.?list-grade(1), '~~', <Barb>, 'List grade 1';

  cmp-ok $roster.?list-all, '~~', ('Grade 1', <Barb>, 'Grade 2', <Jim Zoe>), 'List all';

  ok $roster.?add-student(:name($_), :1grade), "Add $_ to grade 1" for <Charlie Anna>;
  ok $roster.?add-student(:name('Alex'), :2grade), 'Add Alex to grade 2';
  ok $roster.?add-student(:name($_), :3grade), "Add $_ to grade 3" for <Tom Dick Harry>;

  cmp-ok $roster.?list-grade(1), '~~', <Anna Barb Charlie>, 'List grade 1';
  cmp-ok $roster.?list-grade(2), '~~', <Alex Jim Zoe>, 'List grade 2';
  cmp-ok $roster.?list-grade(3), '~~', <Dick Harry Tom>, 'List grade 3';
  cmp-ok $roster.?list-all, '~~', ('Grade 1', <Anna Barb Charlie>, 'Grade 2', <Alex Jim Zoe>, 'Grade 3', <Dick Harry Tom>), 'List all';

unit: module
example: |-
  class Roster is export {
    has %!roster;

    method add-student (Str:D :$name!, Int:D :$grade!) {
      %!roster.append($grade, $name);
    }

    method list-grade (Int:D $grade --> Seq:D) {
      %!roster{$grade}.sort;
    }

    method list-all {
      my @list.append("Grade $_", %!roster{$_}.sort) for %!roster.keys.sort;
      return @list;
    }
  }
stub: |-
  class Roster is export {
  }

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.179 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.178 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.177 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.176 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.175 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.174 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.173 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.172 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.171 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.170 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.169 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.167 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.166 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.165 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.164 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.163 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.162 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.161 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml
trackler-2.2.1.160 tracks/perl6/exercises/grade-school/.meta/exercise-data.yaml