Skip to content
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

Adding unit testing for ModelSystem and AtomsState #15

Merged
merged 36 commits into from
Apr 29, 2024

Conversation

JosePizarro3
Copy link
Collaborator

@JosePizarro3 JosePizarro3 commented Mar 4, 2024

Adding unit testing for the model_system.py and atoms_state.py

@JosePizarro3 JosePizarro3 added the testing Testing additions or fixes label Mar 4, 2024
@JosePizarro3 JosePizarro3 self-assigned this Mar 4, 2024
@JosePizarro3 JosePizarro3 linked an issue Mar 4, 2024 that may be closed by this pull request
5 tasks
@JosePizarro3
Copy link
Collaborator Author

JosePizarro3 commented Mar 5, 2024

@ladinesa @ndaelman-hu before continuing adding tests, would you mind checking these I prepared? Do they align with the idea you have for doing unit testing?

When preparing them, I wanted to test each of the functions defined for the base classes (including normalize()).

tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@ladinesa ladinesa left a comment

Choose a reason for hiding this comment

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

the tests are written in the way i expected, did not check the coverage so please have a look,

@JosePizarro3
Copy link
Collaborator Author

the tests are written in the way i expected, did not check the coverage so please have a look,

Great, thanks a lot!

Indeed, I am aligning the repo with the other plugins #14, so I will check the coverage.

@JosePizarro3 JosePizarro3 force-pushed the 9-adding-unit-testing branch 2 times, most recently from fed99f2 to 9027215 Compare March 5, 2024 10:40
@coveralls
Copy link

coveralls commented Mar 5, 2024

Pull Request Test Coverage Report for Build 8876276556

Details

  • 271 of 272 (99.63%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.1%) to 98.17%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tests/conftest.py 25 26 96.15%
Totals Coverage Status
Change from base Build 8875734593: 1.1%
Covered Lines: 590
Relevant Lines: 601

💛 - Coveralls

@JosePizarro3
Copy link
Collaborator Author

@ndaelman-hu would you mind having a look at this? I prepared some testing for atoms_state.py and model_system.py. I will initially merge this, then continue adding testing for model_method.

@JosePizarro3
Copy link
Collaborator Author

@ndaelman-hu would you mind taking a look on this? Just a quick check, I have to still rebase to your conftest, and keep writing tests for ModelSystem, it is more the general structure, if you agree or not.

Copy link
Collaborator

@ndaelman-hu ndaelman-hu left a comment

Choose a reason for hiding this comment

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

(Disclaimer: only checked the AtomState tester. Will do ModelSystem some other time.)
Overall, it lies in-line with my understanding of unit testing, yes. Good work.

Please double-check the test values I marked. I think those need to be tweaked.

Comment on lines 50 to 65
@pytest.mark.parametrize(
'number, values, results',
[
('n_quantum_number', [-1, 0, 1, 2], [False, False, True, True]),
('l_quantum_number', [-2, 0, 1, 2], [False, False, True, True]),
# l_quantum_number == 2 when testing 'ml_quantum_number'
('ml_quantum_number', [-3, 5, -2, 1], [False, False, True, True]),
('ms_quantum_number', [0, 10, -0.5, 0.5], [False, False, True, True]),
],
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would extend the coverage here, since you can be exhaustive (at least for the True responses: the False are a pain).
Maybe a series of nested for-loops are more appropriate here than the pytest.mark.parametrize decorator?
Question: what about states that contain multiple electrons?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean now you've only covered n=2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Question: what about states that contain multiple electrons?

Here I am only defining orbital states, not the electronic one. I think the electronic could be define a posteriori using some normalization, that's why I open a discussion #22, so that we can safely define electronic state from OrbitalsState

tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
[
([3.0, 2.0, 1.0], (0.1429146, -0.0357286, 0.0893216)),
(None, (None, None, None)),
([3.0, 2.0, 1.0, 0.5], (None, None, None)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this last example test? An incorrect no. passed integrals by whom?
I'd rather see more integrals tested..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, but the functionality does not support it, there is a warning in the function.

tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
tests/test_atoms_state.py Outdated Show resolved Hide resolved
@JosePizarro3 JosePizarro3 force-pushed the 9-adding-unit-testing branch 7 times, most recently from d3a766f to 19a3b86 Compare April 11, 2024 12:53
@JosePizarro3 JosePizarro3 force-pushed the 9-adding-unit-testing branch from 1125cd0 to bae8ccd Compare April 29, 2024 08:45
@JosePizarro3
Copy link
Collaborator Author

@ladinesa would you mind giving a last final quick look? I understand this pr is big so it will take time, but I am just aiming for a quick double-check (the tests are already thought of).

I can then continue adding test to the ModelMethod.

@JosePizarro3 JosePizarro3 removed the request for review from ndaelman-hu April 29, 2024 09:24
@JosePizarro3 JosePizarro3 merged commit a7412b2 into develop Apr 29, 2024
4 checks passed
@JosePizarro3 JosePizarro3 deleted the 9-adding-unit-testing branch April 29, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Testing additions or fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding unit testing
4 participants