Skip to content

Commit

Permalink
Update test_indep_var_comp.py
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjasa committed Apr 24, 2024
1 parent 114f07e commit bd461f7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions openmdao/core/tests/test_indep_var_comp.py
Expand Up @@ -105,6 +105,52 @@ def test_add_output(self):
assert_near_equal(prob.get_val('indep_var_1'), 1.0)
assert_near_equal(prob.get_val('indep_var_2'), 2.0)

def test_tuple_ivc(self):
"""Define one independent variable using a tuple."""

ivcs = [
('indep_var', 1.0),
('indep_var2', 2.0),
]

comp = om.IndepVarComp(ivcs)

prob = om.Problem()
prob.model.add_subsystem('comp', comp, promotes=['*'])
prob.setup(check=False)

assert_near_equal(prob.get_val('indep_var'), 1.0)
assert_near_equal(prob.get_val('indep_var2'), 2.0)

def test_tuple_ivc_kwargs(self):
"""Define one independent variable using a tuple with additional options."""

ivcs = [
('indep_var', 1.0, {'units': 'm'}),
('indep_var2', 2.0, {'units': 'm'}),
]

comp = om.IndepVarComp(ivcs)

prob = om.Problem()
prob.model.add_subsystem('comp', comp, promotes=['*'])
prob.setup(check=False)

assert_near_equal(prob.get_val('indep_var', units='m'), 1.0)
assert_near_equal(prob.get_val('indep_var2', units='m'), 2.0)

def test_tuple_error(self):
"""Test to see if the objects in the list are actually tuples."""

ivcs = ['indep_var', 'indep_var2']

try:
om.IndepVarComp(ivcs)
except TypeError as err:
self.assertEqual(str(err), "Each entry in the list of tuples must be of type tuple.")
else:
self.fail('Exception expected.')

def test_promote_glob_no_inputs(self):
p = om.Problem()
p.model.add_subsystem('indep',
Expand Down

0 comments on commit bd461f7

Please sign in to comment.