Skip to content

Commit

Permalink
unit test added for SimsoptRequires
Browse files Browse the repository at this point in the history
  • Loading branch information
mbkumar committed Dec 23, 2021
1 parent 7e2906d commit f611e74
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/util/test_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest

try:
import numpy as np
except ImportError:
np = None

from simsopt.util.dev import SimsoptRequires, deprecated
from simsopt._core.graph_optimizable import Optimizable

@SimsoptRequires(np is not None, "numpy is not installed.")
class TestClass(Optimizable):
def __init__(self):
x = np.array([1.2, 0.9, -0.4])
fixed = np.full(3, False)
super().__init__(x0=x, fixed=fixed)

def J(self):
return np.exp(self.full_x[0] ** 2 - np.exp(self.full_x[1]) \
+ np.sin(self.full_x[2]))

return_fn_map = {'J': J}

class SimsoptRequiresTest(unittest.TestCase):
def test_instance_check(self):
tf = TestClass()
self.assertIsInstance(tf, TestClass)


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

0 comments on commit f611e74

Please sign in to comment.