Skip to content

Commit 3820e85

Browse files
author
Onur R. Bingol
committed
Add more tests for the utilities module
1 parent 6f42a99 commit 3820e85

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

tests/test_utils.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import pytest
99
from geomdl import utilities
1010

11+
GEOMDL_DELTA = 10e-8
12+
1113

1214
def test_generate_knot_vector1():
1315
with pytest.raises(ValueError):
@@ -63,6 +65,13 @@ def test_check_knot_vector4():
6365
assert check_result
6466

6567

68+
def test_check_knot_vector5():
69+
degree = 4
70+
num_ctrlpts = 12
71+
with pytest.raises(TypeError):
72+
utilities.check_knot_vector(degree=degree, num_ctrlpts=num_ctrlpts, knot_vector=5)
73+
74+
6675
def test_normalize_knot_vector1():
6776
# check for empty list/tuple
6877
with pytest.raises(ValueError):
@@ -76,6 +85,11 @@ def test_normalize_knot_vector2():
7685
assert to_check == output_kv
7786

7887

88+
def test_normalize_knot_vector3():
89+
with pytest.raises(TypeError):
90+
utilities.normalize_knot_vector(5)
91+
92+
7993
def test_check_uv1():
8094
with pytest.raises(ValueError):
8195
u = -0.1
@@ -128,6 +142,11 @@ def test_vector_dot2():
128142
assert to_check == result
129143

130144

145+
def test_vector_dot3():
146+
with pytest.raises(TypeError):
147+
utilities.vector_dot(5, 9.7)
148+
149+
131150
def test_vector_cross1():
132151
with pytest.raises(ValueError):
133152
vec1 = ()
@@ -150,6 +169,11 @@ def test_vector_cross3():
150169
assert to_check == result
151170

152171

172+
def test_vector_cross4():
173+
with pytest.raises(TypeError):
174+
utilities.vector_cross(5, 9.7)
175+
176+
153177
def test_vector_normalize1():
154178
with pytest.raises(ValueError):
155179
vec = ()
@@ -162,6 +186,11 @@ def test_vector_normalize2():
162186
utilities.vector_normalize(vec)
163187

164188

189+
def test_vector_normalize3():
190+
with pytest.raises(TypeError):
191+
utilities.vector_normalize(5)
192+
193+
165194
def test_vector3_normalize():
166195
vec = (5, 2.5, 5)
167196
result = [0.667, 0.333, 0.667]
@@ -194,7 +223,12 @@ def test_vector_generate2():
194223
assert to_check_normalized == result_normalized
195224

196225

197-
def test_vector_translate1():
226+
def test_vector_generate3():
227+
with pytest.raises(TypeError):
228+
utilities.vector_generate(5, 9.7)
229+
230+
231+
def test_point_translate1():
198232
with pytest.raises(ValueError):
199233
pt1 = ()
200234
pt2 = (1, 2, 3)
@@ -209,6 +243,11 @@ def test_point_translate2():
209243
assert to_check == result
210244

211245

246+
def test_point_translate3():
247+
with pytest.raises(TypeError):
248+
utilities.point_translate(5, 9.7)
249+
250+
212251
def test_binomial_coefficient1():
213252
result = 0.0
214253
to_check = utilities.binomial_coefficient(13, 14)
@@ -227,7 +266,7 @@ def test_binomial_coefficient3():
227266
assert to_check == result
228267

229268

230-
def test_frange():
269+
def test_frange1():
231270
start = 5
232271
stop = 11
233272
step = 2
@@ -238,6 +277,16 @@ def test_frange():
238277
assert to_check == result
239278

240279

280+
def test_frange2():
281+
check = list(utilities.frange(0, 1, 0.1))
282+
result = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
283+
check_flag = True
284+
for c, r in zip(check, result):
285+
if abs(c - r) > GEOMDL_DELTA:
286+
check_flag = False
287+
assert check_flag
288+
289+
241290
def test_color_generator():
242291
seed = 17 # some number to be used as the random seed
243292
result = utilities.color_generator(seed)

0 commit comments

Comments
 (0)