Skip to content

Commit 80184f3

Browse files
committed
VectorArray Integration Tests
1 parent 3574fc0 commit 80184f3

5 files changed

Lines changed: 243 additions & 17 deletions

File tree

pytest.ini

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