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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
extern crate chrono;
#[macro_use]
extern crate lazy_static;
extern crate regex;
extern crate reqwest;
extern crate serde;
pub mod bus;
pub mod bus_enums;
pub mod crowd;
pub mod lta_client;
pub mod taxi;
pub mod traffic;
pub mod train;
pub mod utils;
#[cfg(test)]
mod tests {
use std::env;
use std::fmt::Debug;
use crate::crowd::passenger_vol::VolType;
use crate::lta_client::*;
use crate::utils::commons::Result;
use crate::{bus, crowd, taxi, traffic, train};
fn run_test_and_print<F, T>(f: F)
where
F: Fn(<AClient) -> Result<T>,
T: Debug,
{
let api_key = env::var("API_KEY").unwrap();
let client = LTAClient::with_api_key(api_key);
let res = f(&client);
match res {
Ok(r) => println!("{:?}", r),
Err(e) => println!("{:?}", e),
}
}
#[test]
fn get_arrivals() {
println!("get_arrivals");
let api_key = env::var("API_KEY").unwrap();
let client = LTAClient::with_api_key(api_key);
let res = bus::get_arrival(&client, 83139, "15").unwrap();
let arr = res.services[0].next_bus_as_arr();
println!("{:?}", &res);
println!("{:?}", arr);
}
#[test]
fn get_bus_services() {
println!("get_bus_services");
run_test_and_print(|c| bus::get_bus_services(c));
}
#[test]
fn get_bus_routes() {
println!("get_bus_routes");
run_test_and_print(|c| bus::get_bus_routes(c));
}
#[test]
fn get_bus_stops() {
println!("get_bus_stops");
run_test_and_print(|c| bus::get_bus_stops(c));
}
#[test]
fn get_passenger_vol() {
println!("get_passenger_vol");
run_test_and_print(|c| crowd::get_passenger_vol_by(c, VolType::OdTrain));
}
#[test]
fn get_taxi_avail() {
println!("get_taxi_avail");
run_test_and_print(|c| taxi::get_taxi_avail(c));
}
#[test]
fn get_erp_rates() {
println!("get_erp_rates");
run_test_and_print(|c| traffic::get_erp_rates(c));
}
#[test]
fn get_cp_avail() {
println!("get_cp_avail");
run_test_and_print(|c| traffic::get_carpark_avail(c));
}
#[test]
fn get_est_travel_time() {
println!("get_est_travel_time");
run_test_and_print(|c| traffic::get_est_travel_time(c));
}
#[test]
fn get_faulty_traffic_lights() {
println!("get_faulty_traffic_lights");
run_test_and_print(|c| traffic::get_faulty_traffic_lights(c));
}
#[test]
fn get_road_details() {
println!("get_road_details");
use traffic::road::RoadDetailsType::RoadWorks;
run_test_and_print(|c| traffic::get_road_details(c, RoadWorks));
}
#[test]
fn get_traffic_images() {
println!("get_traffic_images");
run_test_and_print(|c| traffic::get_traffic_images(c));
}
#[test]
fn get_traffic_incidents() {
println!("get_traffic_incidents");
run_test_and_print(|c| traffic::get_traffic_incidents(c));
}
#[test]
fn get_traffic_speed_band() {
println!("get_traffic_speed_band");
run_test_and_print(|c| traffic::get_traffic_speed_band(c));
}
#[test]
fn get_vms() {
println!("get_vms");
run_test_and_print(|c| traffic::get_vms_emas(c));
}
#[test]
fn get_bike_parking() {
println!("get_bike_parking");
run_test_and_print(|c| traffic::get_bike_parking(c, 1.364897, 103.766094, 0.5));
}
#[test]
fn get_train_service_alerts() {
println!("get_train_service_alerts");
run_test_and_print(|c| train::get_train_service_alert(c));
}
}