1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
# -*- perl -*-
use strict;
use Set::IntSpan 1.17;
my $N = 1;
sub Not { print "not " }
sub OK { print "ok ", $N++, "\n" }
my @Island =
# cover holes
([' - ', ' - ', ' - ',],
[' (-) ', ' (-) ', ' - ',],
[' (-1,9-) ', ' (-) ', ' 2-8 ',],
[' (-0 ', ' (-0 ', ' - ',],
[' (-0,5-9 ', ' (-9 ', ' 1-4 ',],
[' 0-) ', ' 0-) ', ' - ',],
[' 0-5,9-) ', ' 0-) ', ' 6-8 ',],
[' 1 ', ' 1 ', ' - ',],
[' 5 ', ' 5 ', ' - ',],
[' 1,3,5 ', ' 1-5 ', ' 2,4 ',],
[' 1,3-5 ', ' 1-5 ', ' 2 ',],
['-1-5 ', '-1-5 ', ' - ',],
);
my @Inset =
(
[ ' - ', -2, ' - ' ],
[ ' - ', -1, ' - ' ],
[ ' - ', 0, ' - ' ],
[ ' - ', 1, ' - ' ],
[ ' - ', 2, ' - ' ],
[ '(-)', -2, '(-)' ],
[ '(-)', -1, '(-)' ],
[ '(-)', 0, '(-)' ],
[ '(-)', 1, '(-)' ],
[ '(-)', 2, '(-)' ],
[ '(-0', -2, '(-2 ' ],
[ '(-0', -1, '(-1 ' ],
[ '(-0', 0, '(-0 ' ],
[ '(-0', 1, '(--1' ],
[ '(-0', 2, '(--2' ],
[ '0-)', -2, '-2-)' ],
[ '0-)', -1, '-1-)' ],
[ '0-)', 0, ' 0-)' ],
[ '0-)', 1, ' 1-)' ],
[ '0-)', 2, ' 2-)' ],
[ '0,2-3,6-8,12-15,20-24,30-35' , -2, '-2-26,28-37' ],
[ '0,2-3,6-8,12-15,20-24,30-35' , -1, '-1-9,11-16,19-25,29-36' ],
[ '0,2-3,6-8,12-15,20-24,30-35' , 0, '0,2-3,6-8,12-15,20-24,30-35' ],
[ '0,2-3,6-8,12-15,20-24,30-35' , 1, '7,13-14,21-23,31-34' ],
[ '0,2-3,6-8,12-15,20-24,30-35' , 2, '22,32-33' ],
[ '(-0,2-3,6-8,12-15,20-24,30-35', -2, '(-26,28-37' ],
[ '(-0,2-3,6-8,12-15,20-24,30-35', -1, '(-9,11-16,19-25,29-36' ],
[ '(-0,2-3,6-8,12-15,20-24,30-35', 0, '(-0,2-3,6-8,12-15,20-24,30-35' ],
[ '(-0,2-3,6-8,12-15,20-24,30-35', 1, '(--1,7,13-14,21-23,31-34' ],
[ '(-0,2-3,6-8,12-15,20-24,30-35', 2, '(--2,22,32-33' ],
[ '0,2-3,6-8,12-15,20-24,30-)' , -2, '-2-26,28-)' ],
[ '0,2-3,6-8,12-15,20-24,30-)' , -1, '-1-9,11-16,19-25,29-)' ],
[ '0,2-3,6-8,12-15,20-24,30-)' , 0, '0,2-3,6-8,12-15,20-24,30-)' ],
[ '0,2-3,6-8,12-15,20-24,30-)' , 1, '7,13-14,21-23,31-)' ],
[ '0,2-3,6-8,12-15,20-24,30-)' , 2, '22,32-)' ],
);
print "1..", 2 * (@Island+1) + (@Inset+2), "\n";
Cover();
Holes();
Inset();
sub Cover
{
print "#cover\n";
for my $t (@Island)
{
my $set = new Set::IntSpan $t->[0];
my $expected = new Set::IntSpan $t->[1];
my $result = $set->cover;
printf "#%-12s %-12s -> %s\n", 'cover', $set->run_list, $result->run_list;
$result->equal($expected) or Not; OK;
}
Set::IntSpan->new->extent->empty or Not; OK;
}
sub Holes
{
print "#holes\n";
for my $t (@Island)
{
my $set = new Set::IntSpan $t->[0];
my $expected = new Set::IntSpan $t->[2];
my $result = $set->holes;
printf "#%-12s %-12s -> %s\n", 'holes', $set->run_list, $result->run_list;
$result->equal($expected) or Not; OK;
}
Set::IntSpan->new->holes->empty or Not; OK;
}
sub Inset
{
print "#inset\n";
for my $t (@Inset)
{
my $set = new Set::IntSpan $t->[0];
my $n = $t->[1];
my $expected = new Set::IntSpan $t->[2];
my $result = $set->inset($n);
printf "#%-12s %-12s %d -> %s\n", 'inset', $set->run_list, $n, $result->run_list;
$result->equal($expected) or Not; OK;
}
Set::IntSpan->new('1-3')->pad (1)->size==5 or Not; OK;
Set::IntSpan->new('1-3')->trim(1)->size==1 or Not; OK;
}
|