exercise: GradeSchool version: 3 plan: 18 tests: |- subtest "Roster class methods", { plan 3; ok ::('Roster').can($_), $_ for ; } my $roster = ::('Roster').new; ok $roster.?add-student(:name('Jim'), :2grade), 'Add Jim to grade 2'; cmp-ok $roster.?list-grade(2), '~~', , '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), '~~', , 'List grade 2'; cmp-ok $roster.?list-grade(1), '~~', , 'List grade 1'; cmp-ok $roster.?list-all, '~~', ('Grade 1', , 'Grade 2', ), 'List all'; ok $roster.?add-student(:name($_), :1grade), "Add $_ to grade 1" for ; ok $roster.?add-student(:name('Alex'), :2grade), 'Add Alex to grade 2'; ok $roster.?add-student(:name($_), :3grade), "Add $_ to grade 3" for ; cmp-ok $roster.?list-grade(1), '~~', , 'List grade 1'; cmp-ok $roster.?list-grade(2), '~~', , 'List grade 2'; cmp-ok $roster.?list-grade(3), '~~', , 'List grade 3'; cmp-ok $roster.?list-all, '~~', ('Grade 1', , 'Grade 2', , 'Grade 3', ), '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 { }