Skip to content

test(#22): add unit tests for essential functions - #31

Closed
gausshj wants to merge 6 commits into
mainfrom
test/22-pytest-essential-functions
Closed

test(#22): add unit tests for essential functions#31
gausshj wants to merge 6 commits into
mainfrom
test/22-pytest-essential-functions

Conversation

@gausshj

@gausshj gausshj commented Aug 6, 2025

Copy link
Copy Markdown
Collaborator

This PR adds unit tests for essential tensor functions related to issue #22.

✅ Completed items:

  • arithmetic
  • masking
  • permute

⏳ Remaining:

  • reverse
  • split edge
  • merge edge
  • contract
  • trace
  • conjugate
  • svd
  • qr
  • identity
  • exponential

@gausshj gausshj changed the title Test/22 pytest essential functions test(#22): add unit tests for arithmetic Aug 6, 2025
@gausshj gausshj changed the title test(#22): add unit tests for arithmetic test(#22): add unit tests for essential functions Aug 6, 2025
@@ -0,0 +1,198 @@
"""
[#22](https://github.com/hzhangxyz/parity_tensor/issues/22)
Test essential functions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

不要把对各个功能的测试集中在一个文件中,也不要把各个测试的改动集中在一个PR里,提交一个完整的PR就很好了。
不要在测试文件中标注这个,以后看代码的人如果真的想知道这个代码怎么来的,他可以用git blame。

[#22](https://github.com/hzhangxyz/parity_tensor/issues/22)
Test essential functions.
"""
from typing import Tuple

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这个是老版本的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])))])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fixture的name可以直接使用函数的名称,不需要这样设置的,

# Test __pos__ method.
print("-" * 5, "Test __pos__ method", "-" * 5)
print(parity_tensor)
print(+parity_tensor)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

不要在测试中使用print来输出到屏幕,不会有人对此进行任何检查。

@gausshj gausshj closed this Aug 8, 2025
@gausshj
gausshj deleted the test/22-pytest-essential-functions branch August 8, 2025 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants