condor-pathfinding-grid 0.4.0

Grid pathfinding, preprocessing, replanning, and multi-agent algorithms for Condor.
Documentation
//! Shared assertions for fixture-free grid_core integration smokes.
//!
//! Helpers keep path presence, exact cost, and walkability checks consistent
//! across weighted and uniform Pathfinder cases without pulling harness corpora.

use condor_grid::{Grid, Path, Point, SearchOutcome, SearchStats};

type GridOutcome = SearchOutcome<Path, SearchStats>;

/// Asserts `Found` and returns the path payload for further checks.
pub fn expect_found_path<'a>(outcome: &'a GridOutcome, algorithm: &str, fixture: &str) -> &'a Path {
    assert!(
        outcome.is_found(),
        "{algorithm} should find the {fixture} fixture"
    );
    outcome
        .path()
        .unwrap_or_else(|| panic!("{algorithm} should return a path for the {fixture} fixture"))
}

/// Asserts the outcome reports exactly `expected_cost` (destination-cell model).
pub fn assert_exact_path_cost(
    result: &GridOutcome,
    expected_cost: usize,
    algorithm: &str,
    fixture: &str,
) {
    assert_eq!(
        result.cost(),
        Some(expected_cost),
        "{algorithm} should preserve exact cost for the {fixture} fixture"
    );
}

/// Asserts a completed no-path outcome (no path payload, no cost).
pub fn assert_no_path(outcome: &GridOutcome, algorithm: &str, fixture: &str) {
    assert!(
        !outcome.is_found(),
        "{algorithm} should report no path for the {fixture} fixture"
    );
    assert!(
        outcome.path().is_none(),
        "{algorithm} should not return a bogus path"
    );
    assert_eq!(
        outcome.cost(),
        None,
        "{algorithm} should not report a path cost"
    );
}

/// Asserts endpoints, walkability, and 4-connected unit steps along `path`.
pub fn assert_path_valid(
    grid: &Grid,
    path: &[Point],
    start: Point,
    goal: Point,
    algorithm: &str,
    fixture: &str,
) {
    assert_eq!(
        path.first(),
        Some(&start),
        "{algorithm} path should start at request start"
    );
    assert_eq!(
        path.last(),
        Some(&goal),
        "{algorithm} path should end at request goal"
    );

    for step in path {
        assert!(
            grid.contains(*step),
            "{algorithm} returned an out-of-bounds step"
        );
        assert!(
            grid.is_walkable(*step),
            "{algorithm} returned a blocked step"
        );
    }

    for pair in path.windows(2) {
        let dx = pair[0].x.abs_diff(pair[1].x);
        let dy = pair[0].y.abs_diff(pair[1].y);
        assert_eq!(
            dx + dy,
            1,
            "{algorithm} path for {fixture} must use cardinal moves"
        );
    }
}