Newer
Older
NetAddr-IP / t / v4-hostenum.t
  1. use NetAddr::IP;
  2.  
  3. # $Id: v4-hostenum.t,v 1.1.1.1 2006/08/14 15:36:06 lem Exp $
  4.  
  5. my %addr = (
  6. '10.0.0.0' => [ '255.255.255.252',
  7. [
  8. '10.0.0.1', '10.0.0.2',
  9. ]],
  10. '11.0.0.0' => [ '255.255.255.255',
  11. [
  12. '11.0.0.0',
  13. ]],
  14. '12.0.0.0' => [ '255.255.255.0',
  15. []],
  16. );
  17.  
  18. for my $o (1..254) {
  19. push @{$addr{'12.0.0.0'}->[1]}, '12.0.0.' . $o;
  20. }
  21.  
  22. my $count = $| = 1;
  23. print "1..", (2 * scalar keys %addr), "\n";
  24.  
  25. for my $a (keys %addr) {
  26. my $ip = new NetAddr::IP $a, $addr{$a}->[0];
  27. my @r = $ip->hostenum;
  28. my @m = ();
  29.  
  30. if (scalar @r == @{$addr{$a}->[1]}) {
  31. print "ok ", $count++, "\n";
  32. }
  33. else {
  34. print "not ok ", $count++, " (number $a)\n";
  35. }
  36.  
  37. for my $r (@r) {
  38. push @m, grep { $_ eq $r->addr } @{$addr{$a}->[1]};
  39. }
  40.  
  41. if (scalar @m == scalar @r) {
  42. print "ok ", $count++, "\n";
  43. }
  44. else {
  45. print "not ok ", $count++, " (match $a)\n";
  46. print "henum=", join(', ', (map { $_->addr } @r)), "\n";
  47. print "match=", join(', ', @m), "\n";
  48.  
  49. }
  50. }