Skip to content

Add set data test cases #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/diffpy/srmise/tests/test_dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,32 @@ def test___eq__():
"y": np.array([3, 2, 1]),
"res": 4,
},
DataClusters(x=np.array([1, 2, 3]), y=np.array([3, 2, 1]), res=4),
{
"x": np.array([1, 2, 3]),
"y": np.array([3, 2, 1]),
"res": 4,
"data_order": [2, 1, 0],
"clusters": np.array([[0, 0]]),
"current_idx": 2,
"lastpoint_idx": 0,
"INIT": 0,
"READY": 1,
"CLUSTERING": 2,
"DONE": 3,
"lastcluster_idx": None,
"status": 1,
},
),
],
)
def test_set_data(inputs, expected):
actual = DataClusters(x=np.array([]), y=np.array([]), res=0)
actual.setdata(x=inputs["x"], y=inputs["y"], res=inputs["res"])
assert expected == actual

actual = DataClusters(x=inputs["x"], y=inputs["y"], res=inputs["res"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is better. Strinctly this still doesn't test set_data alone. It tests the object constructor. I think this is ok, but we may want to make clear and set_data as private functions. Then we don't need tests (or docstrings in prinicple) for them and we just test the constructor (the __init__).

Whether or not to do this depends where else these functions rae used. Do we want to make them available to users to use, or are they just being used in init alone or in init and a few other places.

These are small things, but once we touch the code we want to leave it better than when we arrived, and it is also a good learning experience.....

Could you look how these two functions are used and we can decide. If we make them private functions we can leave this test as it is but just change its name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is better. Strinctly this still doesn't test set_data alone. It tests the object constructor. I think this is ok, but we may want to make clear and set_data as private functions. Then we don't need tests (or docstrings in prinicple) for them and we just test the constructor (the __init__).

Whether or not to do this depends where else these functions rae used. Do we want to make them available to users to use, or are they just being used in init alone or in init and a few other places.

These are small things, but once we touch the code we want to leave it better than when we arrived, and it is also a good learning experience.....

Could you look how these two functions are used and we can decide. If we make them private functions we can leave this test as it is but just change its name.

I'm certain that these two functions are only used in the constructor. It should be OK to change them into private functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super, let's do this. Just

  • change the name of this test to something like test_DataClusters_constructor since this is what it does anyway.
  • add an underscore to the beginning of the clear and set_data functions. You can leave the docstring since we already wrote it.
  • revisit the test_clear tests. We want to remove this test, but let's make sure that this behavior is being tested in the constructor test, so move over anything we need from there.

attributes = vars(actual)
for attr_key, attr_val in attributes.items():
if isinstance(attr_val, np.ndarray):
assert np.array_equal(attr_val, expected[attr_key])
else:
assert attr_val == expected[attr_key]


@pytest.mark.parametrize(
Expand Down