Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MargaretDuff committed Sep 30, 2024
1 parent b69da73 commit eaaf66e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Wrappers/Python/test/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ def test_gd_armijo_rosen(self):
gd.solution.array[0], self.scipy_opt_high.x[0], atol=1e-2)
np.testing.assert_allclose(
gd.solution.array[1], self.scipy_opt_high.x[1], atol=1e-2)

def test_gd_run_no_iterations(self):
gd = GD(initial=self.initial, objective_function=self.f, step_size=0.002)
with self.assertRaises(ValueError):
gd.run()

def test_gd_run_infinite(self):
gd = GD(initial=self.initial, objective_function=self.f, step_size=0.002)
with self.assertRaises(ValueError):
gd.run(np.inf)

class StopCallback(callbacks.Callback):
def __init__(self):
self.count = 0
def __call__(self, algorithm):
self.count += 1
if self.count == 10:
raise StopIteration
with self.assertWarns(UserWarning):
gd.run(np.inf, callbacks=[StopCallback()])
self.assertEqual(gd.iteration, 9)


class TestFISTA(CCPiTestClass):
Expand Down

0 comments on commit eaaf66e

Please sign in to comment.