summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--t/31-result-basics.t72
-rw-r--r--t/32-result-messages.t56
-rw-r--r--t/33_result-route.t99
3 files changed, 227 insertions, 0 deletions
diff --git a/t/31-result-basics.t b/t/31-result-basics.t
new file mode 100644
index 0000000..206134c
--- /dev/null
+++ b/t/31-result-basics.t
@@ -0,0 +1,72 @@
+#!/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");
+}
diff --git a/t/32-result-messages.t b/t/32-result-messages.t
new file mode 100644
index 0000000..4e30355
--- /dev/null
+++ b/t/32-result-messages.t
@@ -0,0 +1,56 @@
+#!/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');
+}
diff --git a/t/33_result-route.t b/t/33_result-route.t
new file mode 100644
index 0000000..08c096d
--- /dev/null
+++ b/t/33_result-route.t
@@ -0,0 +1,99 @@
+#!/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');