Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase of testing coverage #339

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions open-codegen/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import opengen as og
import subprocess
import logging
import numpy as np


class RustBuildTestCase(unittest.TestCase):
Expand Down Expand Up @@ -527,6 +528,26 @@ def test_tcp_manager_remote_port_no_ip(self):
with self.assertRaises(Exception) as __context:
_remote_tcp_manager = og.tcp.OptimizerTcpManager(port=8888)

def test_set_y(self):
c = og.constraints.Ball2(radius=1)
y_calc = og.builder.SetYCalculator(c)
y = y_calc.obtain()

def test_squared_norm(self):
u = np.array([3, 4])
y = og.functions.norm2_squared(u)
self.assertAlmostEqual(25., y, places=12)

u = [3, 4]
y = og.functions.norm2_squared(u)
self.assertAlmostEqual(25., y, places=12)

u = cs.SX.sym("u", 2)
f = og.functions.norm2_squared(u)
fun = cs.Function('fun', [u], [f])
y = fun([3, 4])
self.assertAlmostEqual(25., y, places=12)


if __name__ == '__main__':
logging.getLogger('retry').setLevel(logging.ERROR)
Expand Down
30 changes: 30 additions & 0 deletions open-codegen/test/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ def test_cartesian_sx(self):
_sqd_sx = cartesian.distance_squared(u_sx)
u_mx = cs.SX.sym("u", 9, 1)
_sqd_mx = cartesian.distance_squared(u_mx)
self.assertEqual(2, cartesian.segment_dimension(0))
self.assertEqual(3, cartesian.segment_dimension(1))

def test_cartesian_segments_not_increasing(self):
no_constraints = og.constraints.NoConstraints()
Expand Down Expand Up @@ -343,6 +345,24 @@ def test_cartesian_segments_empty_args(self):
with self.assertRaises(ValueError) as __context:
og.constraints.CartesianProduct([], sets)

def test_cartesian_convex(self):
ball_inf = og.constraints.BallInf(None, 1)
ball_eucl = og.constraints.Ball2(None, 1)
cartesian = og.constraints.CartesianProduct(
[5, 10], [ball_inf, ball_eucl])
self.assertTrue(cartesian.is_convex())
self.assertTrue(cartesian.is_compact())

finite_set = og.constraints.FiniteSet([[1, 2, 3], [4, 5, 6]])
cartesian = og.constraints.CartesianProduct(
[5, 10, 13], [ball_inf, ball_eucl, finite_set])
self.assertFalse(cartesian.is_convex())

free = og.constraints.NoConstraints()
cartesian = og.constraints.CartesianProduct(
[5, 10, 11], [ball_inf, ball_eucl, free])
self.assertFalse(cartesian.is_compact())

# -----------------------------------------------------------------------
# Finite Set
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -375,6 +395,10 @@ def test_finite_set_compact(self):
c = og.constraints.FiniteSet([[1, 2, 3], [4, 5, 6]])
self.assertTrue(c.is_compact())

def test_finite_set_dimension(self):
c = og.constraints.FiniteSet([[1, 2, 3], [4, 5, 6]])
self.assertEqual(3, c.dimension())

# -----------------------------------------------------------------------
# Halfspaces
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -513,6 +537,12 @@ def test_sphere2_sq_distance_symbolic(self):
z = fun([1, 1, 0, 0])
self.assertAlmostEqual(0.835786437626905, z, places=12)

def test_sphere2_no_center(self):
sphere = og.constraints.Sphere2(radius=0.5)
u = [0, 0, 0, 0]
dist = sphere.distance_squared(u)
self.assertAlmostEqual(0.25, dist, places=12)


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