1use strict; 2use warnings; 3 4use FindBin qw($Bin); 5use lib $Bin; 6 7use Test::More qw(no_plan); 8 9use Algorithm::Combinatorics qw(combinations); 10use Tester; 11 12my $tester = Tester->__new(\&combinations); 13 14my (@result, @expected); 15 16# --------------------------------------------------------------------- 17 18eval { combinations() }; 19ok($@, ''); 20 21eval { combinations([1]) }; 22ok($@, ''); 23 24eval { combinations(0, 0) }; 25ok($@, ''); 26 27# --------------------------------------------------------------------- 28 29@expected = ([]); 30$tester->__test(\@expected, [], 0); 31 32@expected = ([]); 33$tester->__test(\@expected, [1, 2], 0); 34 35# --------------------------------------------------------------------- 36 37@expected = (["foo"]); 38$tester->__test(\@expected, ["foo"], 1); 39 40# --------------------------------------------------------------------- 41 42@expected = (["foo"], ["bar"]); 43$tester->__test(\@expected, ["foo", "bar"], 1); 44 45# --------------------------------------------------------------------- 46 47@expected = (["foo", "bar"]); 48$tester->__test(\@expected, ["foo", "bar"], 2); 49 50# --------------------------------------------------------------------- 51 52@expected = ( 53 ["foo", "bar"], 54 ["foo", "baz"], 55 ["bar", "baz"], 56); 57$tester->__test(\@expected, ["foo", "bar", "baz"], 2); 58 59# --------------------------------------------------------------------- 60 61@expected = ( 62 ["foo", "bar", "baz"], 63 ["foo", "bar", "zoo"], 64 ["foo", "baz", "zoo"], 65 ["bar", "baz", "zoo"], 66); 67$tester->__test(\@expected, ["foo", "bar", "baz", "zoo"], 3); 68 69# ---------------------------------------------------------------------- 70 71@expected = ( 72 [1, 2, 3], 73 [1, 2, 4], 74 [1, 2, 5], 75 [1, 3, 4], 76 [1, 3, 5], 77 [1, 4, 5], 78 [2, 3, 4], 79 [2, 3, 5], 80 [2, 4, 5], 81 [3, 4, 5], 82); 83$tester->__test(\@expected, [1..5], 3); 84 85# ---------------------------------------------------------------------- 86 87my $ncomb = 0; 88my $iter = combinations([1..20], 15); 89while (my $c = $iter->next) { 90 ++$ncomb; 91} 92is($ncomb, 15504, ""); 93