| 1 | 1 | ▶ | use NetAddr::IP::Lite; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | my @pairs = | |||||||||
| 5 | ( | ||||||||||
| 6 | [ '::/0', '0', '0' ], | ||||||||||
| 7 | [ '::/128', '0', '340282366920938463463374607431768211455' ], | ||||||||||
| 8 | [ 'cafe:cafe::/64', | ||||||||||
| 9 | '269827015721314068804783158349174669312', | ||||||||||
| 10 | '340282366920938463444927863358058659840' ], | ||||||||||
| 11 | [ 'cafe:cafe::1/64', | ||||||||||
| 12 | '269827015721314068804783158349174669313', | ||||||||||
| 13 | '340282366920938463444927863358058659840' ], | ||||||||||
| 14 | [ 'dead:beef::/100', | ||||||||||
| 15 | '295990755014133383690938178081940045824', | ||||||||||
| 16 | '340282366920938463463374607431499776000' ], | ||||||||||
| 17 | [ 'dead:beef::1/100', | ||||||||||
| 18 | '295990755014133383690938178081940045825', | ||||||||||
| 19 | '340282366920938463463374607431499776000' ], | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 1 | my @scale = | |||||||||
| 23 | qw( | ||||||||||
| 24 | 0000:0000:0000:0000:0000:0000:0000:0000 | ||||||||||
| 25 | 0000:0000:0000:0000:0000:0000:0000:0001 | ||||||||||
| 26 | 0000:0000:0000:0000:0000:0000:0000:0010 | ||||||||||
| 27 | 0000:0000:0000:0000:0000:0000:0000:0100 | ||||||||||
| 28 | 0000:0000:0000:0000:0000:0000:0000:1000 | ||||||||||
| 29 | 0000:0000:0000:0000:0000:0000:0001:0000 | ||||||||||
| 30 | 0000:0000:0000:0000:0000:0001:0000:0000 | ||||||||||
| 31 | 0000:0000:0000:0000:0000:0010:0000:0000 | ||||||||||
| 32 | 0000:0000:0000:0000:0000:0100:0000:0000 | ||||||||||
| 33 | 0000:0000:0000:0000:0000:1000:0000:0000 | ||||||||||
| 34 | 0000:0000:0000:0000:0001:0000:0000:0000 | ||||||||||
| 35 | 0000:0000:0000:0001:0000:0000:0000:0000 | ||||||||||
| 36 | 0000:0000:0000:0010:0000:0000:0000:0000 | ||||||||||
| 37 | 0000:0000:0000:0100:0000:0000:0000:0000 | ||||||||||
| 38 | 0000:0000:0000:1000:0000:0000:0000:0000 | ||||||||||
| 39 | 0000:0000:0001:0000:0000:0000:0000:0000 | ||||||||||
| 40 | 0000:0001:0000:0000:0000:0000:0000:0000 | ||||||||||
| 41 | 0000:0010:0000:0000:0000:0000:0000:0000 | ||||||||||
| 42 | 0000:0100:0000:0000:0000:0000:0000:0000 | ||||||||||
| 43 | 0000:1000:0000:0000:0000:0000:0000:0000 | ||||||||||
| 44 | 0001:0000:0000:0000:0000:0000:0000:0000 | ||||||||||
| 45 | 0010:0000:0000:0000:0000:0000:0000:0000 | ||||||||||
| 46 | 0100:0000:0000:0000:0000:0000:0000:0000 | ||||||||||
| 47 | 1000:0000:0000:0000:0000:0000:0000:0000 | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | 1 | my $tests = 4 * @pairs + @scale ** 2; | |||||||||
| 51 | 1 | plan tests => $tests; | |||||||||
| 52 | |||||||||||
| 53 | 1 | for my $p (@pairs) | |||||||||
| 54 | { | ||||||||||
| 55 | 6 | my $a = new NetAddr::IP::Lite $p->[0]; | |||||||||
| 56 | 6 | isa_ok($a, 'NetAddr::IP::Lite', "$p->[0]"); | |||||||||
| 57 | 6 | is($a->numeric, $p->[1], "$p->[0] Scalar numeric ok"); | |||||||||
| 58 | 6 | is(($a->numeric)[0], $p->[1], "$p->[0] Array numeric ok for network"); | |||||||||
| 59 | 6 | is(($a->numeric)[1], $p->[2], "$p->[0] Array numeric ok for mask"); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | @ip_scale = map { new NetAddr::IP::Lite $_ } @scale; | |||||||||
| 63 | |||||||||||
| 64 | 1 | isa_ok($_, 'NetAddr::IP::Lite', $_->addr) for @ip_scale; | |||||||||
| 65 | |||||||||||
| 66 | 1 | for my $i (0 .. $#ip_scale) | |||||||||
| 67 | { | ||||||||||
| 68 | 24 | for my $l (0 .. $i - 1) | |||||||||
| 69 | { | ||||||||||
| 70 | 276 | ▶ | next if $l >= $i; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 276 | ▶ | unless (ok($ip_scale[$i]->numeric > $ip_scale[$l]->numeric, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | "[$i, $l] $scale[$i] > $scale[$l]")) | ||||||||||
| 73 | { | ||||||||||
| 74 | 0 | diag "assertion [$i]: " . $ip_scale[$i]->numeric . | |||||||||
| 75 | " > " . $ip_scale[$l]->numeric; | ||||||||||
| 76 | } | ||||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 24 | ▶ | next if $i == $#ip_scale; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | 23 | for my $l ($i + 1 .. $#ip_scale) | |||||||||
| 82 | { | ||||||||||
| 83 | 276 | ▶ | next if $l <= $i; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 276 | ▶ | unless (ok($ip_scale[$i]->numeric < $ip_scale[$l]->numeric, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | "[$i, $l] $scale[$i] < $scale[$l]")) | ||||||||||
| 86 | { | ||||||||||
| 87 | 0 | diag "assertion [$i]: " . $ip_scale[$i]->numeric . | |||||||||
| 88 | " < " . $ip_scale[$l]->numeric; | ||||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | } | ||||||||||