Skip to content

Commit

Permalink
fix expand list bug and update test to cover more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar-21 committed Feb 17, 2025
1 parent f1ef795 commit d228c50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parastell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def expand_list(list, num):
num_new_entries = 0

if next_entry - entry > avg_diff:
num_new_entries = int(round(next_entry - entry / avg_diff))
num_new_entries = int(round((next_entry - entry) / avg_diff)) - 1

# Manually append first entry
list_exp = np.append(list_exp, entry)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,26 @@ def test_dagmc_renumbering():


def test_expand_list():
# Make sure new entries are inserted as expected
test_values = np.linspace(1, 10, 10)
exp_expanded_list = np.linspace(1, 10, 19)
expanded_list = expand_list(test_values, 19)
assert np.allclose(exp_expanded_list, expanded_list)

# Make sure no changes are made if list already has the requested number of
# entries
expanded_list = expand_list(test_values, 10)
assert len(expanded_list) == len(test_values)
assert np.allclose(expanded_list, test_values)

# Make sure no changes are made if list has more than the requested number
# of entries
expanded_list = expand_list(test_values, 5)
assert len(expanded_list) == len(test_values)
assert np.allclose(expanded_list, test_values)

# Make sure it works with unevenly spaced entries
test_values = [1, 5, 6, 7, 10]
exp_expanded_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
expanded_list = expand_list(test_values, 10)
assert np.allclose(expanded_list, exp_expanded_list)

0 comments on commit d228c50

Please sign in to comment.