Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmghannam committed Jul 20, 2024
1 parent d07c678 commit da38a08
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ impl Model {
}

let c_filename = std::ffi::CString::new(filename).unwrap();
unsafe {
ffi::SoPlex_readInstanceFile(*self.inner, c_filename.as_ptr());
let success = unsafe {
ffi::SoPlex_readInstanceFile(*self.inner, c_filename.as_ptr())
};

if success == 0 {
panic!("Unexpected failure in reading file: {}", filename);
}
}

Expand Down Expand Up @@ -714,4 +718,18 @@ mod tests {
assert_eq!(result, Status::Optimal);
assert!((lp.obj_val() - 5.0).abs() < 1e-6);
}

#[test]
#[should_panic]
fn read_non_existent_file_panic() {
let mut lp = Model::new();
lp.read_file("i_do_not_exist.lp");
}

#[test]
#[should_panic]
fn read_incorrect_format_file_panic() {
let mut lp = Model::new();
lp.read_file("tests/data/simple.txt");
}
}
24 changes: 24 additions & 0 deletions tests/data/simple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
NAME simple
OBJSENSE
MIN
ROWS
N obj
L c1
L c2
COLUMNS
x1 obj -5
x1 c1 1
x1 c2 4
x2 obj -6
x2 c1 1
x2 c2 7
RHS
rhs c1 5
rhs c2 28
RANGES
BOUNDS
LI bound x1 0
UI bound x1 100
LI bound x2 0
UI bound x2 100
ENDATA

0 comments on commit da38a08

Please sign in to comment.