Skip to content

Commit

Permalink
Add test with logs to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Specy committed Feb 1, 2025
1 parent ebad31c commit 7b89220
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ jobs:
with:
command: test

- name: Test Rust with traces
uses: actions-rs/cargo@v1
env:
CARGO_LOG: "trace"
with:
command: test

publish-crate:
if: startsWith(github.ref, 'refs/tags/v')
needs: [ conformance, test ]
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sprs = { version = "0.11.2", default-features = false }
log = "0.4.11"

[dev-dependencies]
ndarray = "0.16.1"
rand = "0.8.5"
rand_pcg = "0.3.1"
env_logger = "0.11.5"
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,13 @@ pub use mps::MpsFile;
mod tests {
use super::*;

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}

#[test]
fn optimize() {
init();
let mut problem = Problem::new(OptimizationDirection::Maximize);
let v1 = problem.add_var(3.0, (12.0, f64::INFINITY));
let v2 = problem.add_var(4.0, (5.0, f64::INFINITY));
Expand All @@ -586,6 +591,7 @@ mod tests {

#[test]
fn empty_expr_constraints() {
init();
let trivial = [
(LinearExpr::empty(), ComparisonOp::Eq, 0.0),
(LinearExpr::empty(), ComparisonOp::Ge, -1.0),
Expand Down Expand Up @@ -630,6 +636,7 @@ mod tests {

#[test]
fn free_variables() {
init();
let mut problem = Problem::new(OptimizationDirection::Maximize);
let v1 = problem.add_var(1.0, (0.0, f64::INFINITY));
let v2 = problem.add_var(2.0, (f64::NEG_INFINITY, f64::INFINITY));
Expand All @@ -645,6 +652,7 @@ mod tests {

#[test]
fn fix_unfix_var() {
init();
let mut problem = Problem::new(OptimizationDirection::Maximize);
let v1 = problem.add_var(1.0, (0.0, 3.0));
let v2 = problem.add_var(2.0, (0.0, 3.0));
Expand Down Expand Up @@ -680,6 +688,7 @@ mod tests {

#[test]
fn add_constraint() {
init();
let mut problem = Problem::new(OptimizationDirection::Minimize);
let v1 = problem.add_var(2.0, (0.0, f64::INFINITY));
let v2 = problem.add_var(1.0, (0.0, f64::INFINITY));
Expand Down Expand Up @@ -725,6 +734,7 @@ mod tests {

#[test]
fn gomory_cut() {
init();
let mut problem = Problem::new(OptimizationDirection::Minimize);
let v1 = problem.add_var(0.0, (0.0, f64::INFINITY));
let v2 = problem.add_var(-1.0, (0.0, f64::INFINITY));
Expand Down Expand Up @@ -759,6 +769,7 @@ mod tests {

#[test]
fn knapsack_solve() {
init();
let mut problem = Problem::new(OptimizationDirection::Maximize);
let weights = [10, 60, 30, 40, 30, 20, 20, 2];
let values = [1, 10, 15, 40, 60, 90, 100, 15];
Expand Down Expand Up @@ -788,6 +799,7 @@ mod tests {

#[test]
fn dominating_set_solve() {
init();
let mut problem = Problem::new(OptimizationDirection::Minimize);
let vars = [
problem.add_binary_var(1.0),
Expand Down Expand Up @@ -826,6 +838,7 @@ mod tests {

#[test]
fn solve_milp() {
init();
let mut problem = Problem::new(OptimizationDirection::Maximize);

// Define variables with their objective coefficients
Expand Down Expand Up @@ -853,6 +866,7 @@ mod tests {

#[test]
fn solve_big_m() {
init();
let mut problem = Problem::new(OptimizationDirection::Minimize);

let m = 1.0e9;
Expand Down
9 changes: 8 additions & 1 deletion src/lu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ pub fn lu_factorize<'a>(
lower_nnz,
upper_nnz + size,
upper_nnz,
lower_nnz + upper_nnz + size - mat_nnz,
(lower_nnz + upper_nnz + size) as isize - mat_nnz as isize,
);

let res = LUFactors {
Expand Down Expand Up @@ -468,6 +468,10 @@ mod tests {
use crate::helpers::{assert_matrix_eq, to_dense, to_sparse};
use sprs::{CsMat, CsVec, TriMat};

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}

fn mat_from_triplets(rows: usize, cols: usize, triplets: &[(usize, usize, f64)]) -> CsMat<f64> {
let mut mat = TriMat::with_capacity((rows, cols), triplets.len());
for (r, c, val) in triplets {
Expand All @@ -478,6 +482,7 @@ mod tests {

#[test]
fn lu_simple() {
init();
let mat = mat_from_triplets(
3,
4,
Expand Down Expand Up @@ -553,6 +558,7 @@ mod tests {

#[test]
fn lu_singular() {
init();
let size = 3;

{
Expand Down Expand Up @@ -610,6 +616,7 @@ mod tests {

#[test]
fn lu_rand() {
init();
let size = 10;

let mut rng = rand_pcg::Pcg64::seed_from_u64(12345);
Expand Down
8 changes: 8 additions & 0 deletions src/ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ mod tests {
use super::*;
use sprs::{CsMat, TriMat};

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}

fn mat_from_triplets(rows: usize, cols: usize, triplets: &[(usize, usize)]) -> CsMat<f64> {
let mut mat = TriMat::with_capacity((rows, cols), triplets.len());
for (r, c) in triplets {
Expand All @@ -694,6 +698,7 @@ mod tests {

#[test]
fn colamd() {
init();
let mat = mat_from_triplets(
4,
5,
Expand Down Expand Up @@ -724,6 +729,7 @@ mod tests {

#[test]
fn colamd_singular() {
init();
{
let empty_col_mat = mat_from_triplets(3, 3, &[(0, 0), (1, 0), (1, 1), (1, 2)]);
let res = order_colamd(3, |c| {
Expand All @@ -743,6 +749,7 @@ mod tests {

#[test]
fn diag_matching() {
init();
let size = 3;
let mat = mat_from_triplets(
size,
Expand All @@ -757,6 +764,7 @@ mod tests {

#[test]
fn block_diag_form() {
init();
let size = 3;
let mat = mat_from_triplets(
size,
Expand Down
7 changes: 7 additions & 0 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,8 +1562,13 @@ mod tests {
use crate::helpers::{assert_matrix_eq, to_sparse};
use crate::Problem;

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}

#[test]
fn initialize() {
init();
let sol = Solver::try_new(
&[2.0, 1.0],
&[f64::NEG_INFINITY, 5.0],
Expand Down Expand Up @@ -1617,6 +1622,7 @@ mod tests {

#[test]
fn solve_integer_singular_var() {
init();
let mut problem = Problem::new(OptimizationDirection::Minimize);
let x = problem.add_integer_var(1.0, (0, 10));
problem.add_constraint([(x, 30.0)], ComparisonOp::Ge, 90.0);
Expand All @@ -1640,6 +1646,7 @@ mod tests {

#[test]
fn initial_solve() {
init();
let mut sol = Solver::try_new(
&[-3.0, -4.0],
&[f64::NEG_INFINITY, 5.0],
Expand Down
5 changes: 5 additions & 0 deletions src/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,13 @@ impl Display for Error {
mod tests {
use super::*;

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}

#[test]
fn mat_transpose() {
init();
let mut mat = SparseMat::new(2);
mat.push(0, 1.1);
mat.push(1, 2.2);
Expand Down

0 comments on commit 7b89220

Please sign in to comment.