test(#22): add unit tests for essential functions - #31
Closed
gausshj wants to merge 6 commits into
Closed
Conversation
fix: resolve merge conflict in .gitignore and fix some formatting issues
- move test into tests
13 tasks
hzhangxyz
requested changes
Aug 7, 2025
| @@ -0,0 +1,198 @@ | |||
| """ | |||
| [#22](https://github.com/hzhangxyz/parity_tensor/issues/22) | |||
| Test essential functions. | |||
Member
There was a problem hiding this comment.
不要把对各个功能的测试集中在一个文件中,也不要把各个测试的改动集中在一个PR里,提交一个完整的PR就很好了。
不要在测试文件中标注这个,以后看代码的人如果真的想知道这个代码怎么来的,他可以用git blame。
| [#22](https://github.com/hzhangxyz/parity_tensor/issues/22) | ||
| Test essential functions. | ||
| """ | ||
| from typing import Tuple |
Member
There was a problem hiding this comment.
这个是老版本的python type annotation,例如,新版本可以直接使用 tuple[int, int]来替换先前的Tuple[int, int]
| ParityTensor((True, False, True), ((1, 1), (2, 2), (3, 1)), torch.randn([2, 4, 4])), | ||
| ), | ||
| (ParityTensor((True, True, False, False), ((1, 2), (2, 2), (1, 1), (3, 1)), | ||
| torch.randn([3, 4, 2, 4])), ParityTensor((True, True, False, False), ((1, 2), (2, 2), (1, 1), (3, 1)), torch.randn([3, 4, 2, 4])))]) |
Member
There was a problem hiding this comment.
python的格式化工具会根据列表中最后一个元素后是否由逗号来判断是否需要换行,你这个前面2个tuple都是由逗号的,但是第三个没有,所以看起来第三格式很奇怪。
| ), | ||
| (ParityTensor((True, True, False, False), ((1, 2), (2, 2), (1, 1), (3, 1)), | ||
| torch.randn([3, 4, 2, 4])), ParityTensor((True, True, False, False), ((1, 2), (2, 2), (1, 1), (3, 1)), torch.randn([3, 4, 2, 4])))]) | ||
| def _parity_instance_fixture(request: pytest.FixtureRequest) -> Tuple[ParityTensor, ParityTensor]: |
Member
There was a problem hiding this comment.
fixture的name可以直接使用函数的名称,不需要这样设置的,
| # Test __pos__ method. | ||
| print("-" * 5, "Test __pos__ method", "-" * 5) | ||
| print(parity_tensor) | ||
| print(+parity_tensor) |
Member
There was a problem hiding this comment.
不要在测试中使用print来输出到屏幕,不会有人对此进行任何检查。
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds unit tests for essential tensor functions related to issue #22.
✅ Completed items:
⏳ Remaining: