summaryrefslogtreecommitdiff
path: root/t/22-results-via.t
blob: 7bda95451096eac47878a19b4d5325d22b804ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use utf8;

use Encode qw(decode);
use File::Slurp qw(slurp);
use List::Util qw(first);
use Test::More tests => 23;

BEGIN {
	use_ok('Travel::Status::DE::ASEAG');
}
require_ok('Travel::Status::DE::ASEAG');

my $rawstr = slurp('t/in/aseag_20131223T132300');
my ($s, @results);

# via filter in ->results, implicit route_after

$s = Travel::Status::DE::ASEAG->new_from_raw(
	datetime  => DateTime->new(
		year   => 2013,
		month  => 12,
		day    => 23,
		hour   => 10,
		minute => 0,
		time_zone => 'Europe/Berlin'
	),
	raw_str   => $rawstr,
	hide_past => 0,
	stop      => 'Aachen Bushof',
);
@results = $s->results( via => 'Finkensief' );

is( @results, 5, '"Aachen Bushof" via_after Finkensief' );
ok( ( first { $_->line == 25 } @results ),
	'"Aachen Bushof" via_after "Brand" contains line 25' );
ok(
	( first { $_->destination eq 'Stolberg Mühlener Bf.' } @results ),
	'"Aachen Bushof" via_after "Brand" contains dest Stolberg Muehlener Bf.'
);
ok( ( first { $_->line == 1 } @results ),
	'"Aachen Bushof" via_after "Brand" contains line 1' );
ok(
	( first { $_->destination eq 'Schevenhütte' } @results ),
	'"Aachen Bushof" via_after "Brand" contains dest Schevenhuette'
);
is( ( first { $_->line != 1 and $_->line != 25 } @results ),
	undef, '"Aachen Bushof" via_after "Brand" does not contain other lines' );
is(
	(
		first {
			$_->destination ne 'Stolberg Mühlener Bf.'
			  and $_->destination ne 'Schevenhütte';
		}
		@results
	),
	undef,
	'"Aachen Bushof" via_after "Brand" does not contain other dests'
);

# via filter in ->results, explicit route_after

$s = Travel::Status::DE::ASEAG->new_from_raw(
	raw_str   => $rawstr,
	hide_past => 0,
	stop      => 'Aachen Bushof',
);
@results = $s->results(
	via         => 'Finkensief',
	full_routes => 'after'
);

is( @results, 5, '"Aachen Bushof" via_after Finkensief' );
ok( ( first { $_->line == 25 } @results ),
	'"Aachen Bushof" via_after "Brand" contains line 25' );
ok(
	( first { $_->destination eq 'Stolberg Mühlener Bf.' } @results ),
	'"Aachen Bushof" via_after "Brand" contains dest Stolberg Muehlener Bf.'
);
ok( ( first { $_->line == 1 } @results ),
	'"Aachen Bushof" via_after "Brand" contains line 1' );
ok(
	( first { $_->destination eq 'Schevenhütte' } @results ),
	'"Aachen Bushof" via_after "Brand" contains dest Schevenhuette'
);
is( ( first { $_->line != 1 and $_->line != 25 } @results ),
	undef, '"Aachen Bushof" via_after "Brand" does not contain anything else' );
is(
	(
		first {
			$_->destination ne 'Stolberg Mühlener Bf.'
			  and $_->destination ne 'Schevenhütte';
		}
		@results
	),
	undef,
	'"Aachen Bushof" via_after "Brand" does not contain other dests'
);

# via filter in ->results, explicit route_before

$s = Travel::Status::DE::ASEAG->new_from_raw(
	raw_str   => $rawstr,
	hide_past => 0,
	stop      => 'Aachen Bushof',
);
@results = $s->results(
	via         => 'Finkensief',
	full_routes => 'before'
);

is( @results, 5, '"Aachen Bushof" via_before Finkensief' );
ok( ( first { $_->line == 25 } @results ),
	'"Aachen Bushof" via_after "Brand" contains line 25' );
ok(
	( first { $_->destination eq 'Vaals Heuvel' } @results ),
	'"Aachen Bushof" via_after "Brand" contains dest Vaals Heuvel'
);
ok( ( first { $_->line == 1 } @results ),
	'"Aachen Bushof" via_after "Brand" contains line 1' );
ok(
	( first { $_->destination eq 'Lintert Friedhof' } @results ),
	'"Aachen Bushof" via_after "Brand" contains dest Lintert Friedhof'
);
is( ( first { $_->line != 1 and $_->line != 25 } @results ),
	undef, '"Aachen Bushof" via_after "Brand" does not contain anything else' );
is(
	(
		first {
			$_->destination ne 'Vaals Heuvel'
			  and $_->destination ne 'Lintert Friedhof';
		}
		@results
	),
	undef,
	'"Aachen Bushof" via_after "Brand" does not contain other dests'
);