Sha256: 31d111120c506d8fe9e824398555fcaf1606dbdbdc301760625a3e6eebf7473c

Contents?: true

Size: 1.35 KB

Versions: 83

Compression:

Stored size: 1.35 KB

Contents

exercise: Robot
version: 2
methods: name reset-name
plan: 7
tests: |-
  srand 1;
  my $robot = Robot.?new;
  my Str $name = $robot.?name;
  like $name, /^^<[A..Z]>**2 <[0..9]>**3$$/, 'Name matches schema';

  srand 2;
  is $robot.?name, $name, 'Name is persistent';
  srand 1;
  isnt Robot.new.?name, $name, 'New Robot cannot claim previous Robot name';

  srand 1;
  $robot.?reset-name;
  $robot.?reset_name; # Allows next test to still pass for older solutions

  isnt $robot.?name, $name, "'reset-name' cannot use previous Robot name";

  diag "\nCreating 100 robots...";
  push my @names, Robot.new.name for 1..100;
  is @names, @names.unique, 'All names are unique';
  subtest 'Randomness', {
    plan 2;
    isnt @names, @names.sort, 'Names not ordered';
    isnt @names, @names.sort.reverse, 'Names not reverse ordered';
  }

unit: class
example: |-
  subset Name of Str where * ~~ /^<[A..Z]>**2 <[0..9]>**3$/;
  has Name $.name = self.reset-name;

  method reset-name {
    state Promise:D $promise = start ('AA000'..'ZZ999').pick: *;
    state Bool:D %record{Name:D};
    state Int:D $i = 0;

    if $promise.status ~~ 'Kept' {
      ($!name = $promise.result[$i++]) or die 'All names used.';
    } else {
      $!name = ('A'..'Z').roll(2).join ~ (^10).roll(3).join;
    }
    self.reset-name if %record{$!name}:exists;
    %record{$!name} = True;
    return $!name;
  }

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.158 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.157 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.156 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.155 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.154 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.153 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.152 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.151 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.150 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.149 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.148 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.147 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.146 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.145 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.144 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.143 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.142 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.141 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml
trackler-2.2.1.140 tracks/perl6/exercises/robot-name/.meta/exercise-data.yaml