Sha256: 361b23a1eb7f7135e9fb69b6f1d89adc848d42162330561990c36c282224c07f

Contents?: true

Size: 1.3 KB

Versions: 72

Compression:

Stored size: 1.3 KB

Contents

#!/usr/bin/env perl6
use v6;
use Test;
use lib $?FILE.IO.dirname;

my $exercise = 'Robot';
my $version = v1;
my $module = %*ENV<EXERCISM> ?? 'Example' !! $exercise;
plan 8;

use-ok $module or bail-out;
require ::($module);

if ::($exercise).^ver !~~ $version {
  warn "\nExercise version mismatch. Further tests may fail!"
    ~ "\n$exercise is $(::($exercise).^ver.gist). "
    ~ "Test is $($version.gist).\n";
  bail-out 'Example version must match test version.' if %*ENV<EXERCISM>;
}

subtest 'Class methods', {
  ok ::($exercise).can($_), $_ for <name reset-name>;
}

srand 1;
my $robot = ::($exercise).?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 ::($exercise).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, ::($exercise).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';
}

done-testing;

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
trackler-2.2.1.43 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.42 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.41 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.40 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.39 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.38 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.37 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.36 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.35 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.34 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.33 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.32 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.31 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.30 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.29 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.28 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.27 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.26 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.25 tracks/perl6/exercises/robot-name/robot-name.t
trackler-2.2.1.24 tracks/perl6/exercises/robot-name/robot-name.t