1use strict; 2use warnings; 3 4use FindBin qw($Bin); 5use lib $Bin; 6 7use Test::More qw(no_plan); 8 9use Algorithm::Combinatorics qw(tuples); 10use Tester; 11 12my $tester = Tester->__new(\&tuples); 13 14my (@result, @expected); 15 16# --------------------------------------------------------------------- 17 18eval { tuples() }; 19ok($@, ''); 20 21eval { tuples([1]) }; 22ok($@, ''); 23 24eval { tuples(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 = ( 48 ["foo", "bar"], 49 ["bar", "foo"], 50); 51$tester->__test(\@expected, ["foo", "bar"], 2); 52 53# --------------------------------------------------------------------- 54 55@expected = ( 56 ["foo", "bar"], 57 ["foo", "baz"], 58 ["bar", "foo"], 59 ["bar", "baz"], 60 ["baz", "foo"], 61 ["baz", "bar"], 62); 63$tester->__test(\@expected, ["foo", "bar", "baz"], 2); 64 65# --------------------------------------------------------------------- 66 67@expected = ( 68 [0, 1, 2], 69 [0, 1, 3], 70 [0, 2, 1], 71 [0, 2, 3], 72 [0, 3, 1], 73 [0, 3, 2], 74 75 [1, 0, 2], 76 [1, 0, 3], 77 [1, 2, 0], 78 [1, 2, 3], 79 [1, 3, 0], 80 [1, 3, 2], 81 82 [2, 0, 1], 83 [2, 0, 3], 84 [2, 1, 0], 85 [2, 1, 3], 86 [2, 3, 0], 87 [2, 3, 1], 88 89 [3, 0, 1], 90 [3, 0, 2], 91 [3, 1, 0], 92 [3, 1, 2], 93 [3, 2, 0], 94 [3, 2, 1], 95); 96$tester->__test(\@expected, [0..3], 3); 97 98# ---------------------------------------------------------------------- 99 100# n*(n-1)*(n-2)* ... *(n-p+1) 101my $ncomb = 0; 102my $iter = tuples([1..9], 5); 103while (my $c = $iter->next) { 104 ++$ncomb; 105} 106is($ncomb, 15120, ""); 107