Skip to content

Commit 29dd567

Browse files
committed
add seqentialize test
1 parent 7d2aa11 commit 29dd567

File tree

1 file changed

+69
-5
lines changed

1 file changed

+69
-5
lines changed

tests/test_utils/test_connec.py

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def one_polygon():
1414
[0, 1],
1515
[1, 2],
1616
[2, 3],
17+
[3, 4],
1718
[4, 5],
1819
[5, 0],
1920
],
@@ -35,6 +36,7 @@ def two_polygons():
3536
[0, 1],
3637
[1, 2],
3738
[2, 3],
39+
[3, 4],
3840
[4, 5],
3941
[5, 0],
4042
# second, descending.
@@ -61,6 +63,7 @@ def one_line():
6163
[0, 1],
6264
[1, 2],
6365
[2, 3],
66+
[3, 4],
6467
[4, 5],
6568
],
6669
dtype=int,
@@ -81,6 +84,7 @@ def two_lines():
8184
[0, 1],
8285
[1, 2],
8386
[2, 3],
87+
[3, 4],
8488
[4, 5],
8589
# second, descending.
8690
[7, 6],
@@ -96,8 +100,68 @@ def two_lines():
96100
return tl
97101

98102

99-
def test_edges_to_polygons():
100-
"""
101-
test
102-
"""
103-
pass
103+
def test_sequentialize_directed_edges():
104+
# polygon
105+
# as default, it starts at minimum
106+
seq, is_p = gus.utils.connec.sequentialize_edges(
107+
one_polygon(), directed=True
108+
)
109+
assert is_p[0]
110+
assert seq[0] == [0, 1, 2, 3, 4, 5]
111+
112+
seq, is_p = gus.utils.connec.sequentialize_edges(
113+
two_polygons(), directed=True
114+
)
115+
for ip in is_p:
116+
assert ip
117+
assert seq[0] == [0, 1, 2, 3, 4, 5]
118+
assert seq[1] == [6, 10, 9, 8, 7]
119+
120+
seq, is_p = gus.utils.connec.sequentialize_edges(one_line(), directed=True)
121+
assert not is_p[0]
122+
assert seq[0] == [0, 1, 2, 3, 4, 5]
123+
124+
# this one include descending indices.
125+
# it should be able to eliminate 6, as a starting point.
126+
# directed query keeps the direction
127+
seq, is_p = gus.utils.connec.sequentialize_edges(
128+
two_lines(), directed=True
129+
)
130+
for ip in is_p:
131+
assert not ip
132+
assert seq[0] == [0, 1, 2, 3, 4, 5]
133+
assert seq[1] == [10, 9, 8, 7, 6]
134+
135+
136+
def test_sequentialize_edges():
137+
# polygon
138+
# as default, it starts at minimum
139+
seq, is_p = gus.utils.connec.sequentialize_edges(
140+
one_polygon(), directed=False
141+
)
142+
assert is_p[0]
143+
assert seq[0] == [0, 1, 2, 3, 4, 5]
144+
145+
seq, is_p = gus.utils.connec.sequentialize_edges(
146+
two_polygons(), directed=False
147+
)
148+
for ip in is_p:
149+
assert ip
150+
assert seq[0] == [0, 1, 2, 3, 4, 5]
151+
assert seq[1] == [6, 10, 9, 8, 7]
152+
153+
seq, is_p = gus.utils.connec.sequentialize_edges(
154+
one_line(), directed=False
155+
)
156+
assert not is_p[0]
157+
assert seq[0] == [0, 1, 2, 3, 4, 5]
158+
159+
# this one include descending indices.
160+
# non-directed query doesn't keep the direction.
161+
seq, is_p = gus.utils.connec.sequentialize_edges(
162+
two_lines(), directed=False
163+
)
164+
for ip in is_p:
165+
assert not ip
166+
assert seq[0] == [0, 1, 2, 3, 4, 5]
167+
assert seq[1] == [6, 7, 8, 9, 10]

0 commit comments

Comments
 (0)