Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shuds13 committed May 24, 2023
1 parent 3a5a58d commit d396d19
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libensemble/tests/unit_tests/test_allocation_funcs_and_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,33 @@ def test_convert_to_rsets():
clear_resources()


def test_check_H_rows():
exp = np.arange(3)
H_rows = AllocSupport._check_H_rows(exp)
assert isinstance(H_rows, np.ndarray), "_check_H_rows returned unexpected type"
assert np.array_equal(H_rows, exp), f"Output {H_rows} is not as expected"

in_rows_list = [0, 1, 2]
H_rows = AllocSupport._check_H_rows(in_rows_list)
assert isinstance(H_rows, np.ndarray), "_check_H_rows returned unexpected type"
assert np.array_equal(H_rows, exp), f"Output {H_rows} is not as expected"

in_rows_list = range(3)
H_rows = AllocSupport._check_H_rows(in_rows_list)
assert isinstance(H_rows, np.ndarray), "_check_H_rows returned unexpected type"
assert np.array_equal(H_rows, exp), f"Output {H_rows} is not as expected"


def test_check_H_fields():
in_fields = ["x", "num_nodes", "procs_per_node"]
H_fields = AllocSupport._check_H_fields(in_fields)
assert H_fields == in_fields, f"H_fields {H_fields} did not match expected"

in_fields = ["x", "num_nodes", "procs_per_node", "x"]
H_fields = AllocSupport._check_H_fields(in_fields)
assert set(H_fields) == set(in_fields), f"H_fields {H_fields} did not match expected"


if __name__ == "__main__":
test_decide_work_and_resources()
test_als_init_normal()
Expand All @@ -468,3 +495,5 @@ def test_convert_to_rsets():
test_als_all_gen_informed()
test_als_points_by_priority()
test_convert_to_rsets()
test_check_H_rows()
test_check_H_fields()

0 comments on commit d396d19

Please sign in to comment.