Skip to content

Commit

Permalink
test for sphere2 constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaville committed Mar 19, 2024
1 parent cb3547e commit 809f69d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion open-codegen/test/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def test_rectangle_noncompact(self):
self.assertFalse(rect.is_compact())

def test_rectangle_is_orthant(self):
rect = og.constraints.Rectangle([0, float('-inf')], [float('inf'), 0.0])
rect = og.constraints.Rectangle(
[0, float('-inf')], [float('inf'), 0.0])
self.assertTrue(rect.is_orthant())
rect = og.constraints.Rectangle([0, 0], [float('inf'), float('inf')])
self.assertTrue(rect.is_orthant())
Expand Down Expand Up @@ -492,6 +493,17 @@ def test_ball1_project_random_points_center(self):
self.assertLessEqual(
np.dot(e-x_star, x-x_star), 1e-10, "Ball1 optimality conditions failed (2)")

# -----------------------------------------------------------------------
# Sphere2
# -----------------------------------------------------------------------

def test_sphere2_sq_distance(self):
sphere = og.constraints.Sphere2(center=[1, 1, 1, 1], radius=0.5)
self.assertFalse(sphere.is_convex())
u = [1, 1, 0, 0]
dist = sphere.distance_squared(u)
self.assertAlmostEqual(0.835786437626905, dist, places=12)


if __name__ == '__main__':
unittest.main()

0 comments on commit 809f69d

Please sign in to comment.