Skip to content

Commit dc419f1

Browse files
authored
Merge pull request #3 from statiolake/test_source
Test both OnceSource and LineSource instead of AutoSource
2 parents 80e2d70 + 83a6087 commit dc419f1

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/main.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,40 @@ fn main() -> UnitResult {
3030
// proconio
3131
#[proconio_derive::fastout]
3232
fn run_proconio() {
33-
use proconio::input;
34-
use proconio::source::auto::AutoSource;
33+
use proconio::source::{line::LineSource, once::OnceSource, Source};
34+
use std::io::BufReader;
3535

36-
let source = AutoSource::from(
37-
r#"2
36+
run_proconio_for::<OnceSource<BufReader<&[u8]>>>();
37+
run_proconio_for::<LineSource<BufReader<&[u8]>>>();
38+
39+
#[proconio_derive::fastout]
40+
fn run_proconio_for<'a, T: Source<BufReader<&'a [u8]>> + From<&'a str>>() {
41+
use proconio::input;
42+
43+
let source = T::from(
44+
r#"2
3845
3 1 2
3946
6 1 1
4047
"#,
41-
);
48+
);
4249

43-
input! {
44-
from source,
45-
n: usize,
46-
mut plan: [(i32, i32, i32); n], // Vec<(i32, i32, i32)>
50+
input! {
51+
from source,
52+
n: usize,
53+
mut plan: [(i32, i32, i32); n], // Vec<(i32, i32, i32)>
54+
}
55+
56+
plan.insert(0, (0, 0, 0));
57+
let yes = plan.windows(2).all(|w| {
58+
let (t0, x0, y0) = w[0];
59+
let (t1, x1, y1) = w[1];
60+
let time = t1 - t0;
61+
let dist = (x1 - x0).abs() + (y1 - y0).abs();
62+
dist <= time && time % 2 == dist % 2
63+
});
64+
println!("{}", if yes { "Yes" } else { "No" });
65+
assert!(yes);
4766
}
48-
plan.insert(0, (0, 0, 0));
49-
let yes = plan.windows(2).all(|w| {
50-
let (t0, x0, y0) = w[0];
51-
let (t1, x1, y1) = w[1];
52-
let time = t1 - t0;
53-
let dist = (x1 - x0).abs() + (y1 - y0).abs();
54-
dist <= time && time % 2 == dist % 2
55-
});
56-
println!("{}", if yes { "Yes" } else { "No" });
57-
assert!(yes);
5867
}
5968

6069
#[test]

0 commit comments

Comments
 (0)