1###############################################################################
2#                                                                             #
3#        Geo::Postcodes::NO Test Suite 3 - The 'selection' procedure          #
4#        -----------------------------------------------------------          #
5#             Arne Sommer - perl@bbop.org  - 24. 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 3_selection.t'.   #
11#                                                                             #
12###############################################################################
13
14use Test::More tests => 18;
15
16BEGIN { use_ok('Geo::Postcodes::NO') };
17
18###############################################################################
19
20my @loc = qw(3001 3002 3003 3004 3005 3006 3007 3008 3011 3012 3013 3014 3015
21             3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028
22             3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041
23             3042 3043 3044 3045 3046 3047 3048);
24
25my @loc1 = Geo::Postcodes::NO::selection(location => 'DRAMMEN');
26is_deeply(\@loc1, \@loc,                "location => 'DRAMMEN'");
27
28###############################################################################
29
30my @bor = qw(1371 1372 1373 1375 1376 1377 1378 1379 1380 1381 1383 1384 1385
31             1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1399);
32
33my @bor1 = Geo::Postcodes::NO::selection(borough    => 'ASKER');
34is_deeply(\@bor1, \@bor,                "borough    => 'ASKER'");
35
36my @bor2 = Geo::Postcodes::NO::selection(borough    => 'asker');
37is_deeply(\@bor2, \@bor,                "borough    => 'asker'");
38
39###############################################################################
40
41my @bno  = qw(9990 9991);
42my @bno1 = Geo::Postcodes::NO::selection(borough_number => '2028');
43is_deeply(\@bno1, \@bno,                "borough_number => '2028'");
44
45###############################################################################
46
47my @cou  = qw(9170 9171 9172 9173 9174 9175 9176 9177 9178 9179);
48my @cou1 = Geo::Postcodes::NO::selection(county     => 'SVALBARD');
49is_deeply(\@cou1, \@cou,                "county     => 'SVALBARD'");
50
51###############################################################################
52
53my @typ = qw(1602 1714 2226 2326 2418 2626 2808 2809 2810 3504 3601 4509 4604
54             4605 4606 4808 4809 4898 5020 5409 6025 6405 6504 6706 6807 7004
55	     7005 7366 7462 7463 7483 7484 7485 7486 7488 7489 7491 7492 7493
56	     7495 7496 7498 7499 7506 7609 7659 7728 7729 7809 8002 8037 8038
57	     8039 8041 8205 8305 8375 8405 8446 8452 8512 8607 8654 8805 8905
58	     9291 9292 9293 9294 9296 9306 9479 9480 9613 9712 9755 9815 9917);
59my @typ1 = Geo::Postcodes::NO::selection(type       => 'SX');
60is_deeply(\@typ1, \@typ,                "type       => 'SX'");
61
62my @typ2 = Geo::Postcodes::NO::selection(type_verbose => 'Serviceboks');
63is_deeply(\@typ2, \@typ,                "type         => 'Serviceboks'");
64
65###############################################################################
66
67my @oo2;
68
69foreach  (Geo::Postcodes::NO::selection(county => 'SVALBARD'))
70{
71  push @oo2, Geo::Postcodes::NO->new($_);
72}
73
74my @oo1 = Geo::Postcodes::NO->selection(county => 'SVALBARD');
75  ## As above, but as full Geo::Postcodes::NO objects .
76
77is_deeply(\@oo1, \@oo2, "List of objects");
78
79###############################################################################
80#                                                                             #
81# And now, more advanced examples                                             #
82#                                                                             #
83###############################################################################
84
85my @and  = qw(4200 8200);
86my @and1 = Geo::Postcodes::NO::selection('and', postcode => '[48]200');
87my @and2 = Geo::Postcodes::NO::selection('and', postcode => '.200',
88                                                location => '%u%');
89
90is_deeply(\@and1, \@and, "selection('and', ...");
91is_deeply(\@and2, \@and, "selection('and', ...");
92
93###############################################################################
94
95my @double  = qw(3650 3666 5457 7105 7119);
96my @double1 = Geo::Postcodes::NO::selection('and', location => '%bygd',
97                                                   borough  => '%i(.)\1%');
98  # Postcodes where the locatation ends with 'bygd', and where the borough
99  # has an 'i' in the name, followeb by two identical characters.
100
101is_deeply(\@double1, \@double, "selection('and')");
102
103###############################################################################
104
105is(Geo::Postcodes::NO::selection('and', postcode => '4%',
106                                        postcode => '9%'), undef, 'undef');
107
108###############################################################################
109
110my @or  = qw(3320 3321 5281 5291 6139 6143);
111my @or1 = Geo::Postcodes::NO::selection('or', location => 'f%bygd',
112                                              location => '%fossen');
113
114is_deeply(\@or1, \@or, "selection('or', ...");
115
116###############################################################################
117
118my @not  = qw(6781 6782 6783);
119my @not1 = Geo::Postcodes::NO::selection('not',        location => '%[aeiou���]%');
120my @not2 = Geo::Postcodes::NO::selection('and not',    location => '%[aeiou]%',
121                                                       location => '%[���]%');
122my @not3 = Geo::Postcodes::NO::selection('and', 'not', location => '%[aeiou]%',
123                                                       location => '%[���]%');
124
125is_deeply(\@not1, \@not, "selection('not',        ...");
126is_deeply(\@not2, \@not, "selection('and not',    ...");
127is_deeply(\@not3, \@not, "selection('and', 'not', ...");
128
129###############################################################################
130
131my @all  = sort(Geo::Postcodes::NO::get_postcodes());
132my @all1 = Geo::Postcodes::NO::selection('all');
133
134is_deeply(\@all1, \@all, "selection('all')");
135
136###############################################################################
137