Esempio n. 1
0
void check_find_and_index_queries(const fixture<T,NA>& fix,
                                  const crs_matrix<T,NA>& m)
{
    using idx_t = typename crs_matrix<T,NA>::size_type;

    if(fix.expected_items().empty()) return;

    //check indexed access of stored elements
    for(const auto& x : fix.expected_items()) {
        auto it = m.find(x.row, x.col);
        if(it == m.end() || *it != x.val)
            throw std::logic_error{"crs_matrix, find(row,col) of stored values"};

        if(m.col_index_of(it) != x.col) {
            std::cout << x.row << ", " << x.col << " != " << m.col_index_of(it) << std::endl;
            throw std::logic_error{"crs_matrix, col_index_of(iterator)"};
        }

        if(m.row_index_of(it) != x.row)
            throw std::logic_error{"crs_matrix, row_index_of(iterator)"};

        auto idx = m.index_of(it);
        if(idx.first != x.row || idx.second != x.col)
            throw std::logic_error{"crs_matrix, index_of(iterator)"};
    }

    //check indexed access of non-stored elements
    for(idx_t r = 0; r < m.rows(); ++r) {
        for(idx_t c = 0, cols = m.cols(); c < cols; ++c) {
            bool stored = false;
            for(const auto& x : fix.expected_items()) {
                if(x.row == r && x.col == c) {
                    stored = true;
                    break;
                }
            }
            if(!stored && (m.find(r,c) != m.end()))
                throw std::logic_error{"crs_matrix, find of n/a values"};
        }
    }
}