Skip to content

Commit

Permalink
Some tests breakout
Browse files Browse the repository at this point in the history
  • Loading branch information
korken89 committed May 7, 2019
1 parent 103a442 commit d73d47a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
40 changes: 1 addition & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
//! Note that this is the **API documentation** of **Optimization Engine**; to get started,
//! you would rather check out the [documentation]().
//!
//!
//!
//!
extern crate num;

Expand All @@ -29,39 +26,4 @@ pub mod matrix_operations;
mod mocks;

#[cfg(test)]
mod tests {

#[allow(unused_imports)]
use super::*;

#[allow(unused_imports)]
use core::Optimizer;

use std::num::NonZeroUsize;

#[test]
fn t_access() {
let radius = 0.2;
let box_constraints = constraints::Ball2::new_at_origin_with_radius(radius);
let problem = core::Problem::new(
box_constraints,
super::mocks::my_gradient,
super::mocks::my_cost,
);
let gamma = 0.1;
let tolerance = 1e-6;

let mut fbs_cache =
core::fbs::FBSCache::new(NonZeroUsize::new(2).unwrap(), gamma, tolerance);
let mut fbs_engine = core::fbs::FBSEngine::new(problem, &mut fbs_cache);
let mut u = [0.0; 2];
let mut optimizer = core::fbs::FBSOptimizer::new(&mut fbs_engine);

let status = optimizer.solve(&mut u);

assert!(status.has_converged());
assert!(status.get_norm_fpr() < tolerance);
assert!((-0.14896 - u[0]).abs() < 1e-4);
assert!((0.13346 - u[1]).abs() < 1e-4);
}
}
mod tests;
28 changes: 28 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use super::*;
use core::Optimizer;
use std::num::NonZeroUsize;

#[test]
fn t_access() {
let radius = 0.2;
let box_constraints = constraints::Ball2::new_at_origin_with_radius(radius);
let problem = core::Problem::new(
box_constraints,
super::mocks::my_gradient,
super::mocks::my_cost,
);
let gamma = 0.1;
let tolerance = 1e-6;

let mut fbs_cache = core::fbs::FBSCache::new(NonZeroUsize::new(2).unwrap(), gamma, tolerance);
let mut fbs_engine = core::fbs::FBSEngine::new(problem, &mut fbs_cache);
let mut u = [0.0; 2];
let mut optimizer = core::fbs::FBSOptimizer::new(&mut fbs_engine);

let status = optimizer.solve(&mut u);

assert!(status.has_converged());
assert!(status.get_norm_fpr() < tolerance);
assert!((-0.14896 - u[0]).abs() < 1e-4);
assert!((0.13346 - u[1]).abs() < 1e-4);
}

0 comments on commit d73d47a

Please sign in to comment.