Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-graph/tests/columns_frozen.rs

//! Captured against main a367f9aa, before replacing the Kahn implementation.
use egui::Color32;
use facett_graph::{DepEdge, DepGraphView, DepNode};

fn columns(n: usize, edges: &[(usize, usize)]) -> Vec<usize> {
    DepGraphView::new(
        (0..n)
            .map(|i| DepNode {
                label: i.to_string(),
                sublabel: None,
                color: Color32::WHITE,
            })
            .collect(),
        edges
            .iter()
            .map(|&(from, to)| DepEdge {
                from,
                to,
                via: vec![],
            })
            .collect(),
    )
    .columns()
}

#[test]
fn frozen_dag_columns() {
    assert_eq!(columns(0, &[]), Vec::<usize>::new());
    assert_eq!(columns(4, &[]), [0, 0, 0, 0]);
    assert_eq!(
        columns(6, &[(1, 0), (2, 1), (3, 2), (4, 3), (5, 4)]),
        [0, 1, 2, 3, 4, 5]
    );
    assert_eq!(columns(4, &[(1, 0), (2, 0), (3, 1), (3, 2)]), [0, 1, 1, 2]);
    assert_eq!(
        columns(7, &[(1, 0), (2, 1), (3, 2), (3, 4), (6, 5)]),
        [0, 1, 2, 3, 0, 0, 1]
    );
    assert_eq!(
        columns(3, &[(1, 0), (1, 0), (2, 1), (2, 99), (99, 1)]),
        [0, 1, 2]
    );
}