Commit d47a165b authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add some ::Result tests (todo: detailed message and route tests)

parent f8b052ab
Loading
Loading
Loading
Loading

t/31-result-basics.t

0 → 100644
+72 −0
Original line number Diff line number Diff line
#!/usr/bin/env perl
use strict;
use warnings;
use 5.014;
use utf8;

use DateTime;
use Test::More tests => 434;
use Test::Fatal;

use Travel::Status::DE::IRIS;

my $status = Travel::Status::DE::IRIS->new(
	iris_base => 'file:t/in',
	station   => 'EE',
	datetime  => DateTime->new(
		year      => 2014,
		month     => 1,
		day       => 3,
		hour      => 20,
		minute    => 1,
		time_zone => 'Europe/Berlin'
	)
);

my @results = $status->results;

is(@results, 135, 'got 135 results');

my $ice645 = $results[0];
my $s1 = $results[1];


# Generic checks: All accessors should work

isa_ok($ice645->arrival, 'DateTime');
isa_ok($ice645->datetime, 'DateTime');
isa_ok($ice645->departure, 'DateTime');
isa_ok($ice645->sched_arrival, 'DateTime');
isa_ok($ice645->sched_departure, 'DateTime');
isa_ok($ice645->start, 'DateTime');
is($ice645->datetime, $ice645->sched_departure, 'datetime is sched_departure');
is_deeply(['F'], [$ice645->classes], '->classes');
is($ice645->date, '03.01.2014', '->date');
is($ice645->delay, 53, '->delay');
is($ice645->destination, 'Berlin Ostbahnhof', '->destination');
ok(! $ice645->is_cancelled, '->is_cancelled for non-cancelled train');
is($ice645->line, 'ICE 645', '->line');
is($ice645->line_no, undef, '->line_no');
is($ice645->origin, 'Köln/Bonn Flughafen', '->origin');
is($ice645->platform, 4, '->platform');
is($ice645->raw_id, '1065350279715650378-1401031812-6', '->raw_id');
is($ice645->route_end, 'Berlin Ostbahnhof', '->routd_end');
is($ice645->route_start, 'Köln/Bonn Flughafen', '->routd_start');
is($ice645->sched_route_end, 'Berlin Ostbahnhof', '->sched_route_end');
is($ice645->sched_route_start, 'Köln/Bonn Flughafen', '->sched_routd_start');
is($ice645->stop_no, 6, '->stop_no');
is($ice645->time, '19:23', '->time');
is($ice645->train, 'ICE 645', '->train');
is($ice645->train_id, '1065350279715650378', '->train_id');
is($ice645->train_no, 645, '->train_no');
is($ice645->type, 'ICE', '->type');

ok($s1->is_cancelled, '->is_cancelled for cancelled train');

# documented aliases should work on all results
for my $i (0 .. $#results) {
	my $r = $results[$i];
	is($r->origin, $r->route_start, "results[$i]: origin == route_start");
	is($r->destination, $r->route_end, "results[$i]: destination == routd_end");
	is($r->train, $r->line, "results[$i]: line == train");
}

t/32-result-messages.t

0 → 100644
+56 −0
Original line number Diff line number Diff line
#!/usr/bin/env perl
use strict;
use warnings;
use 5.014;
use utf8;

use DateTime;
use Test::More tests => 4;
use Test::Fatal;

use Travel::Status::DE::IRIS;

my $status = Travel::Status::DE::IRIS->new(
	iris_base => 'file:t/in',
	station   => 'EE',
	datetime  => DateTime->new(
		year      => 2014,
		month     => 1,
		day       => 3,
		hour      => 20,
		minute    => 1,
		time_zone => 'Europe/Berlin'
	)
);

my @results = $status->results;

my $ice645 = $results[0];
my $s1 = $results[1];
my $s9 = $results[8];
my $hkx = $results[10];
my $abr = $results[13];

is_deeply([$ice645->info],
['Witterungsbedingte Störung', 'Unwetter', 'Abweichende Wagenreihung'],
'info: no dups, sorted, msg+qos');

is_deeply([$ice645->messages], [
['2014-01-03T19:03:00', 'Witterungsbedingte Störung'],
['2014-01-03T19:15:00', 'Witterungsbedingte Störung'],
['2014-01-03T19:48:00', 'Witterungsbedingte Störung'],
['2014-01-03T19:58:00', 'Witterungsbedingte Störung'],
['2014-01-03T19:59:00', 'Witterungsbedingte Störung'],
['2014-01-03T20:00:00', 'Witterungsbedingte Störung'],
['2014-01-03T20:01:00', 'Unwetter'],
['2014-01-03T20:02:00', 'Abweichende Wagenreihung']], 'messages: with dups');

is_deeply([$ice645->qos_messages], [
['2014-01-03T20:02:00', 'Abweichende Wagenreihung']], 'qos_messages');

TODO: {
	local $TODO = 'no duplicate finding yet';
	is_deeply([$ice645->delay_messages], [
['2014-01-03T19:03:00', 'Witterungsbedingte Störung'],
['2014-01-03T20:01:00', 'Unwetter']], 'delay_messages: no dups');
}

t/33_result-route.t

0 → 100644
+99 −0
Original line number Diff line number Diff line
#!/usr/bin/env perl
use strict;
use warnings;
use 5.014;
use utf8;

use DateTime;
use Test::More tests => 8;
use Test::Fatal;

use Travel::Status::DE::IRIS;

my $status = Travel::Status::DE::IRIS->new(
	iris_base => 'file:t/in',
	station   => 'EE',
	datetime  => DateTime->new(
		year      => 2014,
		month     => 1,
		day       => 3,
		hour      => 20,
		minute    => 1,
		time_zone => 'Europe/Berlin'
	)
);

my @results = $status->results;

my $ice645 = $results[0];
my $s1     = $results[1];
my $s9     = $results[8];
my $hkx    = $results[10];
my $abr    = $results[13];

is_deeply(
	[ $ice645->route ],
	[ $ice645->sched_route ],
	'route == sched_route'
);
is_deeply(
	[ $ice645->route_pre ],
	[ $ice645->sched_route_pre ],
	'route_pre == sched_route_pre'
);
is_deeply(
	[ $ice645->route_post ],
	[ $ice645->sched_route_post ],
	'route_post == sched_route_post'
);

is_deeply(
	[ $ice645->route ],
	[
		'Köln/Bonn Flughafen',
		'Köln Messe/Deutz Gl.11-12',
		'Düsseldorf Hbf',
		'Düsseldorf Flughafen',
		'Duisburg Hbf',
		'Essen Hbf',
		'Bochum Hbf',
		'Dortmund Hbf',
		'Hamm(Westf)',
		'Bielefeld Hbf',
		'Hannover Hbf',
		'Berlin-Spandau',
		'Berlin Hbf',
		'Berlin Ostbahnhof'
	],
	'route'
);
is_deeply(
	[ $ice645->route_pre ],
	[
		'Köln/Bonn Flughafen',
		'Köln Messe/Deutz Gl.11-12',
		'Düsseldorf Hbf',
		'Düsseldorf Flughafen',
		'Duisburg Hbf'
	],
	'route_pre'
);
is_deeply(
	[ $ice645->route_post ],
	[
		'Bochum Hbf',
		'Dortmund Hbf',
		'Hamm(Westf)',
		'Bielefeld Hbf',
		'Hannover Hbf',
		'Berlin-Spandau',
		'Berlin Hbf',
		'Berlin Ostbahnhof'
	],
	'route_post'
);

is_deeply([$ice645->route_interesting],
	['Bochum', 'Dortmund', 'Bielefeld'], 'route_interesting with just major');
is_deeply([$abr->route_interesting],
	['Essen-Kray Süd', 'Bochum', 'Witten'], 'route_interesting with minor');