use mop_structs::{matrix::csr_matrix::CsrMatrix, prelude::*};

use mop_common::quickcheck::quickcheck;

quickcheck! {

fn csr_matrix_row_iter_next(
    cm: CsrMatrix<Vec<i32>, Vec<usize>>
) -> bool {
    for (row_idx, row) in cm.row_iter().enumerate() {
        if row != cm.row(row_idx) {
            return false;
        }
    }
    true
}

fn csr_matrix_row_iter_next_back(
    cm: CsrMatrix<Vec<i32>, Vec<usize>>
) -> bool {
    let mut i = cm.row_iter();
    let mut idx = cm.rows();
    while let Some(row) = i.next_back() {
        idx -= 1;
        if row != cm.row(idx) {
            return false;
        }
    }
    true
}

fn csr_matrix_row_iter_split_at(
    cm: CsrMatrix<Vec<i32>, Vec<usize>>
) -> bool {
    let split_in = if cm.rows() > 3 { 3 } else { cm.rows() };
    let (first_half, second_half) = cm.row_iter().split_at(split_in);
    for (idx, row) in first_half.enumerate() {
        if row != cm.row(idx) {
            return false;
        }
    }
    for (idx, row) in second_half.enumerate() {
        if row != cm.row(idx + split_in) {
            return false;
        }
    }
    true
}

#[cfg(feature = "parallelization")]
fn csr_matrix_row_par_iter(
    cm: CsrMatrix<Vec<i32>, Vec<usize>>
) -> bool {
    cm.row_par_iter().enumerate().all(|(row_idx, row)| row == cm.row(row_idx))
}

}
