File: unary.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 (59 lines) | stat: -rw-r--r-- 1,144 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
# -*- perl -*-

use strict;
use Set::IntSpan 1.17;

my $N = 1;
sub Not { print "not " }
sub OK  { print "ok ", $N++, "\n" }

sub Table { map { [ split(' ', $_) ] } split(/\s*\n\s*/, shift) }

my @Unaries = Table <<TABLE;
-            (-)
(-1          2-)
1            (-0,2-)
1-3          (-0,4-)
1-3,5-9,15-) (-0,4,10-14
TABLE

print "1..", 4 * @Unaries, "\n";
Complement();


sub Complement
{
    print "#complement\n";

    for my $t (@Unaries)
    {
	Unary("complement", $t->[0], $t->[1]);
	Unary("complement", $t->[1], $t->[0]);
	U    ("C"	  , $t->[0], $t->[1]);
	U    ("C"	  , $t->[1], $t->[0]);
    }
}


sub Unary
{
    my($method, $operand, $expected) = @_;
    my $set = new Set::IntSpan $operand;
    my $setE = $set->$method();
    my $run_list = run_list $setE;

    printf "#%-12s %-10s -> %-10s\n", $method, $operand, $run_list;
    $run_list eq $expected or Not; OK;
}

sub U
{
    my($method, $operand, $expected) = @_;
    my $set = new Set::IntSpan $operand;
    $set->$method();
    my $run_list = run_list $set;

    printf "#%-12s %-10s -> %-10s\n", $method, $operand, $run_list;
    $run_list eq $expected or Not; OK;
}