Skip to content

Commit

Permalink
sphere2: test with no centre
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaville committed Oct 27, 2023
1 parent 352417c commit d227dfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod no_constraints;
mod rectangle;
mod simplex;
mod soc;
mod sphere2;
mod zero;

pub use ball1::Ball1;
Expand All @@ -32,6 +33,7 @@ pub use no_constraints::NoConstraints;
pub use rectangle::Rectangle;
pub use simplex::Simplex;
pub use soc::SecondOrderCone;
pub use sphere2::Sphere2;
pub use zero::Zero;

/// A set which can be used as a constraint
Expand Down
14 changes: 14 additions & 0 deletions src/constraints/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,20 @@ fn t_ball1_random_optimality_conditions_centered() {
}
}

#[test]
fn t_sphere2_no_center() {
let radius = 1.0;
let mut x_out = [1.0, 1.0];
let mut x_in = [1.0, 1.0];
let unit_sphere = Sphere2::new(None, radius);
unit_sphere.project(&mut x_out);
unit_sphere.project(&mut x_in);
let norm_out = crate::matrix_operations::norm2(&x_out);
let norm_in = crate::matrix_operations::norm2(&x_in);
unit_test_utils::assert_nearly_equal(1.0, norm_out, 1e-10, 1e-12, "norm_out is not 1.0");
unit_test_utils::assert_nearly_equal(1.0, norm_in, 1e-10, 1e-12, "norm_in is not 1.0");
}

#[test]
#[should_panic]
fn t_ball1_alpha_negative() {
Expand Down

0 comments on commit d227dfd

Please sign in to comment.