#!perl
my
$map
= new_ok(
'Map::Tube::KoelnBonn'
);
my
$xml
= XMLin(
$map
->xml() ,
KeyAttr
=> [ ],
KeepRoot
=> 1, );
my
(
%lines
,
%stations
);
for
my
$line
( @{
$xml
->{
'tube'
}->{
'lines'
}->{
'line'
} } ) {
my
$id
=
$line
->{
'id'
};
my
$name
=
$line
->{
'name'
};
ok( !
exists
(
$lines
{
$name
} ),
"Line name $name, id $id defined more than once"
);
$lines
{
$name
} = 0;
}
for
my
$station
( @{
$xml
->{
'tube'
}->{
'stations'
}->{
'station'
} } ) {
my
$id
=
$station
->{
'id'
};
my
@lines
=
split
( /,/,
$station
->{
'line'
} );
my
@links
=
split
( /,/,
$station
->{
'link'
} );
isnt(
scalar
(
@lines
), 0,
"Station id $id should have at least one line"
);
isnt(
scalar
(
@links
), 0,
"Station id $id should have at least one link"
);
ok( !
exists
(
$stations
{
$id
} ),
"Station id $id defined more than once"
);
$stations
{
$id
}->{lines}->{
$_
}++
for
@lines
;
$stations
{
$id
}->{links}->{
$_
}++
for
@links
;
ok(
exists
(
$lines
{
$_
} ),
"Station id $id connected by undefined line named $_"
)
for
@lines
;
$lines
{
$_
}++
for
@lines
;
}
for
my
$id
(
keys
%stations
) {
ok(
exists
$stations
{
$_
}->{links}->{
$id
},
"Station id $id linked to id $_ but not vice versa"
)
for
keys
%{
$stations
{
$id
}->{links} };
}
isnt(
$lines
{
$_
}, 0,
"Line named $_ has no stations"
)
for
keys
%lines
;
done_testing();