qrazhan/perl5i — comment on commit 99e6b80ce70698c85478e826e6d420bcc4b6414c
File: t/pick.t line 24
By schwern:

This algorithm doesn't work to detect duplicates, `@rand->as_hash` has already eliminated them.

It's important to make sure your tests fail. You could do this by introducing a bug into pick(). You can also test your test functions. If you structure pick_ok() it becomes testable (good chunk of testing is making things testable).

Essentially what we're doing is a set operation. We want to determine if @rand is a subset of $array. So write an `is_subset` routine just for that. It looks like pick_ok(), but it takes two arrays and returns true or false. Then you write pick_ok() around that.

func pick_ok($array, $num) {
my @picks = $array->pick($num);

my $num_picks = $num > @$array ? @$array : $num;
is @picks, $num_picks;

ok is_subset($array, \@picks), "is_subset" or diag explain \@picks;
}

The advantage is you can test is_subset() directly. `ok is_subset( [1,2,3,4], [1,1,1] )` and `ok is_subset( [1,1,2,2,3,3], [1,1,2] )`;