1############################################################################### 2# # 3# Geo::Postcodes::NO Test Suite 1 - Procedural interface # 4# ------------------------------------------------------ # 5# Arne Sommer - perl@bbop.org - 9. September 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 1_procedures.t'. # 11# # 12############################################################################### 13 14use Test::More tests => 52; 15 16BEGIN { use_ok('Geo::Postcodes::NO') }; 17 18################################################################################# 19 20ok( Geo::Postcodes::NO::legal ("0010"), "Legal postcode"); 21ok( Geo::Postcodes::NO::valid ("0010"), "Postcode in use"); 22ok( Geo::Postcodes::NO::legal ("1178"), "Legal postcode"); 23ok( Geo::Postcodes::NO::valid ("1178"), "Postcode in use"); 24ok( Geo::Postcodes::NO::legal ("2542"), "Legal postcode"); 25ok( Geo::Postcodes::NO::valid ("2542"), "Postcode in use"); 26 27ok( Geo::Postcodes::NO::legal ("0000"), "Legal postcode"); 28ok( ! Geo::Postcodes::NO::valid ("0000"), "Postcode not in use"); 29ok( Geo::Postcodes::NO::legal ("9999"), "Legal postcode"); 30ok( ! Geo::Postcodes::NO::valid ("9999"), "Illegal postcode"); 31 32ok( ! Geo::Postcodes::NO::legal ("10"), "Illegal postcode"); 33ok( ! Geo::Postcodes::NO::valid ("10"), "Illegal postcode"); 34ok( ! Geo::Postcodes::NO::legal ("Ett eller annet"), "Illegal postcode"); 35ok( ! Geo::Postcodes::NO::valid ("Ett eller annet"), "Illegal postcode"); 36 37################################################################################# 38 39my $postcode = "1178"; # My postal code. 40 41is( Geo::Postcodes::NO::location_of ($postcode), "OSLO", "Postcode > Location"); 42is( Geo::Postcodes::NO::borough_number_of($postcode), "0301", "Postcode > Borough number"); 43is( Geo::Postcodes::NO::borough_of ($postcode), "OSLO", "Postcode > Borough"); 44is( Geo::Postcodes::NO::county_of ($postcode), "OSLO", "Postcode > County"); 45is( Geo::Postcodes::NO::borough_number2county (Geo::Postcodes::NO::borough_number_of($postcode)), "OSLO", "Borough number > County"); 46is( Geo::Postcodes::NO::type_of ($postcode), "ST", "Postcode > Type"); 47is( Geo::Postcodes::NO::type_verbose_of ($postcode), "Gateadresse", "Postcode > Type"); 48is( Geo::Postcodes::type_verbose_of ($postcode), undef, "Postcode > Type"); 49 50## Try another one, where the names differ. ##################################### 51 52$postcode = "2542"; # Another one. 53 54is( Geo::Postcodes::NO::location_of ($postcode), "VINGELEN", "Postcode > Location"); 55is( Geo::Postcodes::NO::borough_number_of($postcode), "0436", "Postcode > Borough number"); 56is( Geo::Postcodes::NO::borough_of ($postcode), "TOLGA", "Postcode > Borough"); 57is( Geo::Postcodes::NO::county_of ($postcode), "HEDMARK", "Postcode > County"); 58is( Geo::Postcodes::NO::borough_number2county (Geo::Postcodes::NO::borough_number_of($postcode)), "HEDMARK", "Borough Number > County"); 59is( Geo::Postcodes::NO::type_of ($postcode), "ST", "Postcode > Type"); 60is( Geo::Postcodes::NO::type_verbose_of ($postcode), "Gateadresse", "Postcode > Type"); 61is( Geo::Postcodes::type_verbose_of ($postcode), undef, "Postcode > Type"); 62 63## And now, error handling ###################################################### 64 65is( Geo::Postcodes::NO::location_of ("9999"), undef, "Undef caused by illegal postcode"); 66is( Geo::Postcodes::NO::location_of (undef), undef, "Undef caused by illegal postcode"); 67is( Geo::Postcodes::NO::location_of ("Ett eller annet"), undef, "Undef caused by illegal postcode"); 68 69is( Geo::Postcodes::NO::borough_number_of ("9999"), undef, "Undef caused by illegal postcode"); 70is( Geo::Postcodes::NO::borough_number_of (undef), undef, "Undef caused by illegal postcode"); 71is( Geo::Postcodes::NO::borough_number_of ("Ett eller annet"), undef, "Undef caused by illegal postcode"); 72 73is( Geo::Postcodes::NO::borough_of ("9999"), undef, "Undef caused by illegal postcode"); 74is( Geo::Postcodes::NO::borough_of (undef), undef, "Undef caused by illegal postcode"); 75is( Geo::Postcodes::NO::borough_of ("Ett eller annet"), undef, "Undef caused by illegal postcode"); 76 77is( Geo::Postcodes::NO::borough_number2borough ("9999"), undef, "Undef caused by illegal borough number"); 78is( Geo::Postcodes::NO::borough_number2borough (undef), undef, "Undef caused by illegal borough number"); 79is( Geo::Postcodes::NO::borough_number2borough ("Ett eller annet"), undef, "Undef caused by illegal borough number"); 80 81is( Geo::Postcodes::NO::county_of ("9999"), undef, "Undef caused by illegal postcode"); 82is( Geo::Postcodes::NO::county_of (undef), undef, "Undef caused by illegal postcode"); 83is( Geo::Postcodes::NO::county_of ("Ett eller annet"), undef, "Undef caused by illegal postcode"); 84 85is( Geo::Postcodes::NO::borough_number2county ("9999"), undef, "Undef caused by illegal borough number"); 86is( Geo::Postcodes::NO::borough_number2county (undef), undef, "Undef caused by illegal borough number"); 87is( Geo::Postcodes::NO::borough_number2county ("Ett eller annet"), undef, "Undef caused by illegal borough number"); 88 89is( Geo::Postcodes::NO::type_of ("9999"), undef, "Undef caused by illegal postcode"); 90is( Geo::Postcodes::NO::type_of (undef), undef, "Undef caused by illegal postcode"); 91is( Geo::Postcodes::NO::type_of ("Ett eller annet"), undef, "Undef caused by illegal postcode"); 92 93################################################################################# 94