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