Skip to content

Commit 808b525

Browse files
committed
Merge remote-tracking branch 'origin/feature/integration-tests' into vector-tests
2 parents 2969c6d + 2cfa0be commit 808b525

4 files changed

Lines changed: 229 additions & 17 deletions

File tree

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ markers =
44
integration: Integration tests that check multiple components together
55
core: Core functionality tests
66
synergy: Tests the Synergy class
7+
vector_array: Tests the VectorArray class
78
vector: Tests the Vector class

src/moldflow/vector_array.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ def __init__(self, _vector_array):
2828

2929
def clear(self) -> None:
3030
"""
31-
Clear the vector array.
31+
Resets a vector array - the size of the array is 0 subsequent to this call.
3232
"""
3333
process_log(__name__, LogMessage.FUNCTION_CALL, locals(), name="clear")
3434
self.vector_array.Clear()
3535

36-
def add_xyz(self, x: float, y: float, z: float) -> None:
36+
def add_xyz(self, x: float | int, y: float | int, z: float | int) -> None:
3737
"""
38-
Add a vector to the array with x, y, z values.
38+
Adds a vector (x, y, z) to the end of the array.
3939
4040
Args:
41-
x (float): The x value.
42-
y (float): The y value.
43-
z (float): The z value.
41+
x (float | int): The x component.
42+
y (float | int): The y component.
43+
z (float | int): The z component.
4444
"""
4545
process_log(__name__, LogMessage.FUNCTION_CALL, locals(), name="add_xyz")
4646
check_type(x, (float, int))
@@ -51,23 +51,23 @@ def add_xyz(self, x: float, y: float, z: float) -> None:
5151
@property
5252
def size(self) -> int:
5353
"""
54-
Get the size of the vector array.
54+
Returns the number of vectors in the array.
5555
5656
Returns:
57-
int: The size of the vector array.
57+
The size of the vector array.
5858
"""
5959
process_log(__name__, LogMessage.PROPERTY_GET, locals(), name="size")
6060
return self.vector_array.Size
6161

6262
def x(self, index: int) -> float:
6363
"""
64-
Get the x value of the vector at the index.
64+
Get the x component of the vector at the index.
6565
6666
Args:
67-
index (int): The index of the vector.
67+
index (int): index between 0 and vector_array.size-1 (inclusive)
6868
6969
Returns:
70-
float: The x value of the vector.
70+
The x component of the vector at offset index.
7171
"""
7272
process_log(__name__, LogMessage.PROPERTY_PARAM_GET, locals(), name="x", value=index)
7373
check_type(index, int)
@@ -76,13 +76,13 @@ def x(self, index: int) -> float:
7676

7777
def y(self, index: int) -> float:
7878
"""
79-
Get the y value of the vector at the index.
79+
Get the y component of the vector at the index.
8080
8181
Args:
82-
index (int): The index of the vector.
82+
index (int): index between 0 and vector_array.size-1 (inclusive)
8383
8484
Returns:
85-
float: The y value of the vector.
85+
The y component of the vector at offset index.
8686
"""
8787
process_log(__name__, LogMessage.PROPERTY_PARAM_GET, locals(), name="y", value=index)
8888
check_type(index, int)
@@ -91,13 +91,13 @@ def y(self, index: int) -> float:
9191

9292
def z(self, index: int) -> float:
9393
"""
94-
Get the z value of the vector at the index.
94+
Get the z component of the vector at the index.
9595
9696
Args:
97-
index (int): The index of the vector.
97+
index (int): index between 0 and vector_array.size-1 (inclusive)
9898
9999
Returns:
100-
float: The z value of the vector.
100+
The z component of the vector at offset index.
101101
"""
102102
process_log(__name__, LogMessage.PROPERTY_PARAM_GET, locals(), name="z", value=index)
103103
check_type(index, int)
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# SPDX-FileCopyrightText: 2025 Autodesk, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
Integration tests for VectorArray Wrapper Class of moldflow-api module.
6+
7+
These tests focus on testing the actual functionality and behavior
8+
of the VectorArray class with real Moldflow Synergy COM objects.
9+
"""
10+
11+
import pytest
12+
from moldflow import VectorArray, Synergy
13+
14+
15+
@pytest.mark.integration
16+
@pytest.mark.vector_array
17+
class TestIntegrationVectorArray:
18+
"""
19+
Integration test suite for the VectorArray class.
20+
"""
21+
22+
@pytest.fixture
23+
def vector_array(self, synergy: Synergy):
24+
"""
25+
Fixture to create a real VectorArray instance for integration testing.
26+
"""
27+
return synergy.create_vector_array()
28+
29+
def _check_vector_array_size(self, vector_array: VectorArray, expected_size: int):
30+
"""
31+
Verify the size of the vector array.
32+
"""
33+
assert vector_array.size == expected_size
34+
35+
def _check_vector_at_index(
36+
self, vector_array: VectorArray, index: int, expected_value: list[int | float]
37+
):
38+
"""
39+
Verify the values of a vector at a specific index in the array.
40+
"""
41+
assert vector_array.x(index) == expected_value[0]
42+
assert vector_array.y(index) == expected_value[1]
43+
assert vector_array.z(index) == expected_value[2]
44+
45+
@pytest.mark.synergy
46+
def test_create_vector_array(self, synergy: Synergy):
47+
"""
48+
Test that VectorArray can be created from Synergy instance.
49+
"""
50+
vector_array = synergy.create_vector_array()
51+
self._check_vector_array_size(vector_array, 0)
52+
53+
def test_add_xyz_single_vector(self, vector_array: VectorArray):
54+
"""
55+
Test adding a single vector to the array using add_xyz.
56+
"""
57+
self._check_vector_array_size(vector_array, 0)
58+
59+
vector_array.add_xyz(1.0, 2.0, 3.0)
60+
self._check_vector_array_size(vector_array, 1)
61+
self._check_vector_at_index(vector_array, 0, [1.0, 2.0, 3.0])
62+
63+
@pytest.mark.parametrize(
64+
"vectors",
65+
[
66+
[(1, 2.2, 3.3), (4.4, 5.5, 6.6)],
67+
[(0, 0.0, 0.0), (-1.0, -2, -3.0), (10.5, 20.5, 30)],
68+
[(-5.5, 10.0, 15.5)],
69+
],
70+
)
71+
def test_add_xyz_multiple_vectors(
72+
self, vector_array: VectorArray, vectors: list[tuple[float | int, float | int, float | int]]
73+
):
74+
"""
75+
Test adding multiple vectors to the array.
76+
"""
77+
self._check_vector_array_size(vector_array, 0)
78+
79+
for i, (x, y, z) in enumerate(vectors):
80+
vector_array.add_xyz(x, y, z)
81+
self._check_vector_array_size(vector_array, i + 1)
82+
self._check_vector_at_index(vector_array, i, [x, y, z])
83+
84+
self._check_vector_array_size(vector_array, len(vectors))
85+
for i, (x, y, z) in enumerate(vectors):
86+
self._check_vector_at_index(vector_array, i, [x, y, z])
87+
88+
def test_clear_empty_array(self, vector_array: VectorArray):
89+
"""
90+
Test clearing an empty vector array.
91+
"""
92+
# Initially empty
93+
self._check_vector_array_size(vector_array, 0)
94+
95+
# Clear empty array
96+
vector_array.clear()
97+
self._check_vector_array_size(vector_array, 0)
98+
99+
def test_clear_populated_array(self, vector_array: VectorArray):
100+
"""
101+
Test clearing a populated vector array.
102+
"""
103+
# Add some vectors
104+
test_vectors = [(1.1, 2.2, 3.3), (4.4, 5.5, 6.6), (7.7, 8.8, 9.9)]
105+
for x, y, z in test_vectors:
106+
vector_array.add_xyz(x, y, z)
107+
108+
self._check_vector_array_size(vector_array, len(test_vectors))
109+
110+
# Clear the array
111+
vector_array.clear()
112+
self._check_vector_array_size(vector_array, 0)
113+
114+
def test_vector_array_indexing(self, vector_array: VectorArray):
115+
"""
116+
Test accessing vectors by index in the array.
117+
"""
118+
test_vectors = [(10.1, 20.2, 30.3), (-5.5, 15.5, 25.5), (0.0, 100.0, 200.0)]
119+
120+
# Add test vectors
121+
for x, y, z in test_vectors:
122+
vector_array.add_xyz(x, y, z)
123+
124+
# Test accessing each vector by index
125+
for i, (expected_x, expected_y, expected_z) in enumerate(test_vectors):
126+
self._check_vector_at_index(vector_array, i, [expected_x, expected_y, expected_z])
127+
128+
@pytest.mark.parametrize(
129+
"initial_vectors, additional_vectors, final_vectors",
130+
[([(1.1, 2.2, 3.3), (4.4, 5.5, 6.6)], [(7.7, 8.8, 9.9)], [(10.1, 11.2, 12.3)])],
131+
)
132+
def test_vector_array_state_persistence(
133+
self,
134+
vector_array: VectorArray,
135+
initial_vectors: list[tuple[float, float, float]],
136+
additional_vectors: list[tuple[float, float, float]],
137+
final_vectors: list[tuple[float, float, float]],
138+
):
139+
"""
140+
Test that VectorArray maintains state correctly across multiple operations.
141+
"""
142+
# Add initial vectors
143+
for x, y, z in initial_vectors:
144+
vector_array.add_xyz(x, y, z)
145+
146+
# Verify initial state
147+
self._check_vector_array_size(vector_array, len(initial_vectors))
148+
for i, (x, y, z) in enumerate(initial_vectors):
149+
self._check_vector_at_index(vector_array, i, [x, y, z])
150+
151+
# Add additional vectors
152+
for x, y, z in additional_vectors:
153+
vector_array.add_xyz(x, y, z)
154+
155+
# Verify all vectors are still correct
156+
all_vectors = initial_vectors + additional_vectors
157+
self._check_vector_array_size(vector_array, len(all_vectors))
158+
for i, (x, y, z) in enumerate(all_vectors):
159+
self._check_vector_at_index(vector_array, i, [x, y, z])
160+
161+
# Clear and verify
162+
vector_array.clear()
163+
self._check_vector_array_size(vector_array, 0)
164+
165+
# Add final vectors after clear
166+
for x, y, z in final_vectors:
167+
vector_array.add_xyz(x, y, z)
168+
169+
self._check_vector_array_size(vector_array, len(final_vectors))
170+
for i, (x, y, z) in enumerate(final_vectors):
171+
self._check_vector_at_index(vector_array, i, [x, y, z])
172+
173+
@pytest.mark.parametrize("size", [1, 5, 10])
174+
def test_vector_array_size_property(self, vector_array: VectorArray, size: int):
175+
"""
176+
Test that the size property correctly reflects the number of vectors.
177+
"""
178+
self._check_vector_array_size(vector_array, 0)
179+
180+
for i in range(size):
181+
vector_array.add_xyz(float(i * 1.1), float(i * 2.2), float(i * 3.3))
182+
self._check_vector_array_size(vector_array, i + 1)
183+
184+
self._check_vector_array_size(vector_array, size)
185+
186+
def test_reference_behavior(self, vector_array: VectorArray):
187+
"""
188+
Test reference behavior of VectorArray.
189+
"""
190+
vector_array.add_xyz(1.0, 2.0, 3.0)
191+
vector_array_copy = vector_array
192+
self._check_vector_array_size(vector_array_copy, 1)
193+
self._check_vector_at_index(vector_array_copy, 0, [1.0, 2.0, 3.0])
194+
195+
vector_array_copy.add_xyz(4.0, 5.0, 6.0)
196+
self._check_vector_array_size(vector_array_copy, 2)
197+
self._check_vector_at_index(vector_array_copy, 0, [1.0, 2.0, 3.0])
198+
self._check_vector_at_index(vector_array_copy, 1, [4.0, 5.0, 6.0])
199+
self._check_vector_at_index(vector_array, 1, [4.0, 5.0, 6.0])
200+
201+
vector_array_copy2 = VectorArray(vector_array.vector_array)
202+
self._check_vector_array_size(vector_array_copy2, 2)
203+
self._check_vector_at_index(vector_array_copy2, 0, [1.0, 2.0, 3.0])
204+
self._check_vector_at_index(vector_array_copy2, 1, [4.0, 5.0, 6.0])
205+
206+
vector_array_copy2.add_xyz(7.0, 8.0, 9.0)
207+
self._check_vector_array_size(vector_array_copy2, 3)
208+
self._check_vector_at_index(vector_array_copy2, 0, [1.0, 2.0, 3.0])
209+
self._check_vector_at_index(vector_array_copy2, 1, [4.0, 5.0, 6.0])
210+
self._check_vector_at_index(vector_array_copy2, 2, [7.0, 8.0, 9.0])

tests/api/unit_tests/test_unit_vector_array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
@pytest.mark.unit
13+
@pytest.mark.vector_array
1314
class TestUnitVectorArray:
1415
"""
1516
Test suite for the VectorArray class.

0 commit comments

Comments
 (0)