From 420a755f6d08b6d936dbf87ed5cd9c95fc285caa Mon Sep 17 00:00:00 2001 From: Hao Zhang Date: Mon, 11 Aug 2025 00:54:05 +0800 Subject: [PATCH] Add more tests for creation of Grassmann tensor. --- tests/creation_test.py | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/creation_test.py b/tests/creation_test.py index c832a34..fd8adbc 100644 --- a/tests/creation_test.py +++ b/tests/creation_test.py @@ -2,12 +2,43 @@ import torch from grassmann_tensor import GrassmannTensor +Initialization = tuple[tuple[bool, ...], tuple[tuple[int, int], ...], torch.Tensor] -def test_creation() -> None: - x = GrassmannTensor((False, False), ((2, 2), (1, 3)), torch.randn([4, 4])) + +@pytest.mark.parametrize("x", [ + ((False, False), ((2, 2), (1, 3)), torch.randn([4, 4])), + ((True, False), ((2, 2), (3, 1)), torch.randn([4, 4])), + ((False, True, False), ((1, 1), (2, 2), (1, 1)), torch.randn([2, 4, 2])), +]) +def test_creation_success(x: Initialization) -> None: + GrassmannTensor(*x) + + +@pytest.mark.parametrize("x", [ + ((False,), ((2, 2), (1, 3)), torch.randn([4, 4])), + ((True, False, True), ((2, 2), (3, 1)), torch.randn([4, 4])), + ((False, True), ((1, 1), (2, 2), (1, 1)), torch.randn([2, 4, 2])), +]) +def test_creation_invalid_arrow(x: Initialization) -> None: with pytest.raises(AssertionError): - x = GrassmannTensor((False, False, False), ((2, 2), (1, 3)), torch.randn([4, 4])) + GrassmannTensor(*x) + + +@pytest.mark.parametrize("x", [ + ((False, False), ((2, 2),), torch.randn([4, 4])), + ((True, False), ((2, 2), (1, 1), (3, 1)), torch.randn([4, 4])), + ((False, True, False), ((1, 1), (1, 1)), torch.randn([2, 4, 2])), +]) +def test_creation_invalid_edges(x: Initialization) -> None: with pytest.raises(AssertionError): - x = GrassmannTensor((False, False), ((2, 2), (1, 3), (3, 1)), torch.randn([4, 4])) + GrassmannTensor(*x) + + +@pytest.mark.parametrize("x", [ + ((False, False), ((2, 2), (1, 3)), torch.randn([4, 2])), + ((True, False), ((2, 2), (3, 1)), torch.randn([2, 4])), + ((False, True, False), ((1, 1), (2, 2), (1, 1)), torch.randn([4, 4, 2])), +]) +def test_creation_invalid_shape(x: Initialization) -> None: with pytest.raises(AssertionError): - x = GrassmannTensor((False, False), ((2, 2), (1, 1)), torch.randn([4, 4])) + GrassmannTensor(*x)