-
Notifications
You must be signed in to change notification settings - Fork 7
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
95fc07e
add test cases to test files and make edition to make sure the behavi…
stevenhua0320 28c6ea7
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] ce1d97f
change case in test__eq__ to be compatible with the behavior of setdata
stevenhua0320 0faa2ca
delete text and redundant tests
stevenhua0320 6a011a2
tweaking error message in DataClusters
sbillinge 83eac4c
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] 9f17d25
update test for checking implicit attributes for setdata function
stevenhua0320 9d84a9f
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] 321f47d
update test for setdata function
stevenhua0320 3369069
update test for setdata function
stevenhua0320 3ef8a5b
update setdata test to right format.
stevenhua0320 cbe85f1
update to constructor test & make setdata clear function private
stevenhua0320 759a7e8
final tweaks to tests by Simon
sbillinge 6f29c60
fix actual_attribute typo
sbillinge d102f5f
final refactor of actual_attr
sbillinge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
from copy import copy | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from diffpy.srmise.dataclusters import DataClusters | ||
|
||
|
||
def test_clear(): | ||
# Initialize DataClusters with input parameters | ||
actual = DataClusters(x=np.array([1, 2, 3]), y=np.array([3, 2, 1]), res=4) | ||
expected = DataClusters(x=np.array([]), y=np.array([]), res=0) | ||
# Perform the clear operation | ||
actual.clear() | ||
assert actual == expected | ||
|
||
|
||
def test___eq__(): | ||
actual = DataClusters(np.array([1, 2, 3]), np.array([3, 2, 1]), 0) | ||
expected = DataClusters(np.array([1, 2, 3]), np.array([3, 2, 1]), 0) | ||
actual = DataClusters(np.array([1, 2, 3]), np.array([3, 2, 1]), 1) | ||
expected = DataClusters(np.array([1, 2, 3]), np.array([3, 2, 1]), 1) | ||
assert expected == actual | ||
attributes = vars(actual) | ||
for attr_key, attr_val in attributes.items(): | ||
|
@@ -32,3 +24,66 @@ def test___eq__(): | |
print(f"not-equal test failed on {attr_key}") | ||
assert not expected == actual | ||
attributes.update({attr_key: reset}) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"inputs, expected", | ||
[ | ||
( | ||
{ | ||
"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_DataClusters_constructor(inputs, expected): | ||
actual = DataClusters(x=inputs["x"], y=inputs["y"], res=inputs["res"]) | ||
actual_attributes = vars(actual) | ||
for attr_key, actual_attr_val in actual_attributes.items(): | ||
if isinstance(actual_attr_val, np.ndarray): | ||
assert np.array_equal(actual_attr_val, expected[attr_key]) | ||
else: | ||
assert actual_attr_val == expected[attr_key] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"inputs, msg", | ||
[ | ||
( | ||
{ | ||
"x": np.array([1]), | ||
"y": np.array([3, 2]), | ||
"res": 4, | ||
}, | ||
"Sequences x and y must have the same length.", | ||
), | ||
( | ||
{ | ||
"x": np.array([1]), | ||
"y": np.array([3]), | ||
"res": -1, | ||
}, | ||
"Value of resolution parameter is less than zero. Please rerun specifying a non-negative res", | ||
), | ||
], | ||
) | ||
def test_set_data_order_bad(inputs, msg): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good test, nice job. |
||
with pytest.raises(ValueError, match=msg): | ||
DataClusters(x=inputs["x"], y=inputs["y"], res=inputs["res"]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm certain that these two functions are only used in the constructor. It should be OK to change them into private functions.
There was a problem hiding this comment.
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
test_DataClusters_constructor
since this is what it does anyway.