Sha256: f52a6ef7a9629138a449e154e35bc7d185816b2d37a6043f78a858feb69d2009

Contents?: true

Size: 1.43 KB

Versions: 82

Compression:

Stored size: 1.43 KB

Contents

exercise: GradeSchool
version: 1
plan: 10
imports: Roster
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';
  is $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';
  is $roster.?list-grade(2), <Jim Zoe>, 'List grade 2';
  is $roster.?list-grade(1), <Barb>, 'List grade 1';
  subtest 'Additional students', {
    plan 6;
    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>;
  }
  is $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

82 entries across 82 versions & 1 rubygems

Version Path
trackler-2.2.1.53 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.52 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.51 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.50 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.49 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.48 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.47 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.46 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.45 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.44 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.43 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.42 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.41 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.40 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.39 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.38 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.37 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.36 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.35 tracks/perl6/exercises/grade-school/example.yaml
trackler-2.2.1.34 tracks/perl6/exercises/grade-school/example.yaml