File: utils.rs

package info (click to toggle)
rust-pathfinding 4.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,024 kB
  • sloc: sh: 19; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 975 bytes parent folder | download
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
use pathfinding::utils::*;

#[test]
fn in_direction_start_oob() {
    assert_eq!(move_in_direction((8, 8), (-1, -1), (8, 8)), None);
    assert_eq!(in_direction((8, 8), (-1, -1), (8, 8)).next(), None);
}

#[test]
fn in_direction_end_oob() {
    assert_eq!(move_in_direction((0, 0), (-1, -1), (8, 8)), None);
    assert_eq!(in_direction((0, 0), (-1, -1), (8, 8)).next(), None);
    assert_eq!(move_in_direction((7, 0), (1, -1), (8, 8)), None);
    assert_eq!(in_direction((0, 7), (-1, 1), (8, 8)).next(), None);
}

#[test]
fn in_direction_invalid() {
    assert_eq!(in_direction((0, 8), (-1, 1), (8, 8)).next(), None);
    assert_eq!(in_direction((8, 0), (-1, 1), (8, 8)).next(), None);
    assert_eq!(in_direction((0, 7), (0, 0), (8, 8)).next(), None);
}

#[test]
fn in_direction_valid() {
    assert_eq!(move_in_direction((1, 1), (1, 3), (2, 4)), None);
    assert_eq!(
        in_direction((1, 1), (1, 3), (8, 8)).collect::<Vec<_>>(),
        vec![(2, 4), (3, 7)]
    );
}