1############################################################################### 2# # 3# Geo::Postcodes::NO Test Suite 2 - Object interface # 4# -------------------------------------------------- # 5# Arne Sommer - perl@bbop.org - 19. July 2006 # 6# # 7############################################################################### 8# # 9# Before `make install' is performed this script should be runnable with # 10# `make test'. After `make install' it should work as `perl 2_objects.t'. # 11# # 12############################################################################### 13 14use Test::More tests => 22; 15 16BEGIN { use_ok('Geo::Postcodes::NO') }; 17 18################################################################################# 19 20my $P = Geo::Postcodes::NO->new("1178"); # My postal code. 21isa_ok($P, "Geo::Postcodes::NO"); 22 23is( $P->postcode(), "1178", "Postcode object > Postcode"); 24is( $P->location(), "OSLO", "Postcode object > Borough number"); 25is( $P->borough_number(), "0301", "Postcode object > Borough number"); 26is( $P->borough(), "OSLO", "Postcode object > Borough"); 27is( $P->county(), "OSLO", "Postcode object > County"); 28is( $P->type(), "ST", "Postcode > Type"); 29is( $P->type_verbose(), "Gateadresse", "Postcode > Type"); 30is( $P->Geo::Postcodes::type_verbose(), "Street address", "Postcode > Type"); 31 32## Try another one, where the names differ. ##################################### 33 34my $P2 = Geo::Postcodes::NO->new("2542"); # Another one. 35isa_ok($P2, "Geo::Postcodes::NO"); 36 37is( $P2->postcode(), "2542", "Postcode object > Postcode"); 38is( $P2->location(), "VINGELEN", "Postcode object > Borough number"); 39is( $P2->borough_number(), "0436", "Postcode object > Borough number"); 40is( $P2->borough(), "TOLGA", "Postcode object > Borough"); 41is( $P2->county(), "HEDMARK", "Postcode object > County"); 42is( $P2->type(), "ST", "Postcode > Type"); 43is( $P2->type_verbose(), "Gateadresse", "Postcode > Type"); 44is( $P2->Geo::Postcodes::type_verbose(), "Street address", "Postcode > Type"); 45 46## And now, error handling ###################################################### 47 48my $P3 = Geo::Postcodes::NO->new("9999"); # This postcode is not in use. 49is( $P3, undef, "Undef caused by illegal postcode"); 50 51$P3 = Geo::Postcodes::NO->new(undef); 52is( $P3, undef, "Undef caused by illegal postcode"); 53 54$P3 = Geo::Postcodes::NO->new("Totusensekshundreognoenogtredve"); 55is( $P3, undef, "Undef caused by illegal postcode"); 56 57################################################################################# 58 59