File: ord.t

package info (click to toggle)
libset-intspan-perl 1.19-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 224 kB
  • sloc: perl: 1,236; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (3)
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
# -*- perl -*-

use strict;
use Set::IntSpan 1.17;

my $N = 1;
sub Not { print "not " }
sub OK
{
    my($function, $test) = @_;

    $test ||= [];
    for (@$test) { defined $_ or $_ = '<undef>' }
    my $expected = pop @$test;

    print "ok $N $function: @$test\t-> $expected\n";

    $N++;
}

my @Ord_die =
(
 [ '(-0',  42, '<die>' ],
);

my @Ord_test =
(
 [ '-'	  	    ,  0, undef ],
 [ '0'	  	    ,  0, 0     ],
 [ '1'	  	    ,  0, undef ],
 [ '1'	  	    ,  2, undef ],
 [ '1,3-5'	    ,  0, undef ],
 [ '1,3-5'	    ,  1, 0     ],
 [ '1,3-5'	    ,  2, undef ],
 [ '1,3-5'	    ,  3, 1     ],
 [ '1,3-5'	    ,  4, 2     ],
 [ '1,3-5'	    ,  5, 3     ],
 [ '1,3-5'	    ,  6, undef ],
 [ '1-)'  	    ,  0, undef ],
 [ '1-)'  	    ,  1, 0     ],
 [ '1-)'  	    ,  8, 7     ],
 [ '1-5,11-15,21-25', 21, 10    ],
);

print "1..", @Ord_die + @Ord_test, "\n";

for my $test (@Ord_die)
{
    my($run_list, $n) = @$test;

    eval { Set::IntSpan->new($run_list)->ord($n) };
    $@ or Not; OK("ord", $test);
}

for my $test (@Ord_test)
{
    my($run_list, $n, $i) = @$test;

    equal(Set::IntSpan->new($run_list)->ord($n), $i) or Not; OK("ord", $test);
}

sub equal
{
    my($a, $b) = @_;

    not defined $a and not defined $b or
        defined $a and     defined $b and $a == $b
}