weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
//! Property gates for `weir::graph_layout::stable_csr_layout_hash`.

use proptest::prelude::*;
use weir::graph_layout::stable_csr_layout_hash;

proptest! {
    #![proptest_config(ProptestConfig::with_cases(10_000))]

    #[test]
    fn layout_hash_is_deterministic(
        node_count in 0u32..32,
        edge_count in 0u32..32,
        offsets in proptest::collection::vec(any::<u32>(), 0..=16),
        targets in proptest::collection::vec(any::<u32>(), 0..=16),
        kinds in proptest::collection::vec(any::<u32>(), 0..=16),
    ) {
        let h1 = stable_csr_layout_hash(node_count, edge_count, &offsets, &targets, &kinds);
        let h2 = stable_csr_layout_hash(node_count, edge_count, &offsets, &targets, &kinds);
        prop_assert_eq!(h1, h2);
    }

    #[test]
    fn permuting_edge_arrays_changes_hash_unless_identical(
        node_count in 1u32..8,
        a in any::<u32>(),
        b in any::<u32>(),
    ) {
        let offsets = vec![0, 1];
        let targets_a = vec![a, b];
        let targets_b = vec![b, a];
        let kinds = vec![1u32, 2];
        let h_a = stable_csr_layout_hash(node_count, 2, &offsets, &targets_a, &kinds);
        let h_b = stable_csr_layout_hash(node_count, 2, &offsets, &targets_b, &kinds);
        prop_assume!(a != b);
        prop_assert_ne!(h_a, h_b);
    }

    #[test]
    fn node_count_is_mixed_into_hash(
        offsets in proptest::collection::vec(0u32..4, 2..=4),
        targets in proptest::collection::vec(0u32..4, 2..=4),
        kinds in proptest::collection::vec(1u32..8, 2..=4),
    ) {
        let h0 = stable_csr_layout_hash(0, 2, &offsets, &targets, &kinds);
        let h1 = stable_csr_layout_hash(1, 2, &offsets, &targets, &kinds);
        prop_assert_ne!(h0, h1);
    }

    #[test]
    fn edge_count_is_mixed_into_hash(
        offsets in proptest::collection::vec(0u32..4, 2..=4),
        targets in proptest::collection::vec(0u32..4, 2..=4),
        kinds in proptest::collection::vec(1u32..8, 2..=4),
    ) {
        let h2 = stable_csr_layout_hash(4, 2, &offsets, &targets, &kinds);
        let h3 = stable_csr_layout_hash(4, 3, &offsets, &targets, &kinds);
        prop_assert_ne!(h2, h3);
    }
}