File: union_more.t

package info (click to toggle)
libnumber-tolerant-perl 1.710-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: perl: 757; makefile: 10
file content (81 lines) | stat: -rw-r--r-- 2,144 bytes parent folder | download | duplicates (2)
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
use Test::More tests => 32;

use strict;
use warnings;

BEGIN { use_ok("Number::Tolerant"); }
BEGIN { use_ok("Number::Tolerant::Union"); }

{ # tol | constant
  my $alpha = Number::Tolerant->new(4.5  => to => 5.25);

  isa_ok($alpha, 'Number::Tolerant');

  my $choice = $alpha | 7;

  isa_ok($choice,   'Number::Tolerant::Union', 'union');

  ok(5 == $choice, ' ... 5 == $union');
  ok(6 != $choice, ' ... 6 != $union');
  ok(7 == $choice, ' ... 7 == $union');
  ok(8 != $choice, ' ... 8 != $union');
}

{ # tol | tol | constant
  my $alpha = Number::Tolerant->new(4.5  => to => 5.25);
  my $beta  = Number::Tolerant->new(5.75 => to => 6.25);

  isa_ok($alpha, 'Number::Tolerant');
  isa_ok($beta,  'Number::Tolerant');

  my $choice = $alpha | $beta | 7;

  isa_ok($choice,   'Number::Tolerant::Union', 'union');

  ok(5 == $choice, ' ... 5 == $union');
  ok(6 == $choice, ' ... 6 == $union');
  ok(7 == $choice, ' ... 7 == $union');
  ok(8 != $choice, ' ... 8 != $union');
}

{ # union | union
  my $alpha = Number::Tolerant->new(4.5  => to => 5.25);
  my $beta  = Number::Tolerant->new(5.75 => to => 6.25);

  isa_ok($alpha, 'Number::Tolerant');
  isa_ok($beta,  'Number::Tolerant');

  my $gamma = Number::Tolerant->new(6 => to => 7);
  my $delta = Number::Tolerant->new(1 => to => 2);

  isa_ok($gamma, 'Number::Tolerant');
  isa_ok($delta, 'Number::Tolerant');

  my $c1 = $alpha | $beta;
  my $c2 = $gamma | $delta;

  isa_ok($c1, 'Number::Tolerant::Union', 'union');
  isa_ok($c2, 'Number::Tolerant::Union', 'union');

  my $choice = $c1 | $c2;

  isa_ok($choice,  'Number::Tolerant::Union', 'union');

  ok(5 == $choice, ' ... 5 == $union');
  ok(6 == $choice, ' ... 6 == $union');
  ok(7 == $choice, ' ... 7 == $union');
  ok(8 != $choice, ' ... 8 != $union');
}

{ # union(x..y) like Number::Range

  my $range = Number::Tolerant::Union->new(1..10, 15..20);

  isa_ok($range, 'Number::Tolerant::Union');

  ok( 5.0 == $range, ' ...  5.0 == $union');
  ok( 5.5 != $range, ' ...  5.5 != $range');
  ok( 6.0 == $range, ' ...  6.0 == $union');
  ok(11.0 != $range, ' ... 11.0 == $union');
  ok(15.0 == $range, ' ... 15.0 != $union');
}