Skip to content

Commit 789e036

Browse files
committed
added tests
#205
1 parent e00dfd1 commit 789e036

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/test_utils.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#%%
2+
import sys
3+
sys.path.append('../')
4+
import musicalgestures
5+
from musicalgestures._utils import *
6+
import numpy as np
7+
import os
8+
9+
#%%
10+
class Test_roundup:
11+
def test_positive(self):
12+
assert roundup(10, 4) == 12
13+
def test_negative(self):
14+
assert roundup(-71, 3) == -69
15+
16+
17+
class Test_clamp:
18+
def test_int_hi(self):
19+
assert clamp(100, 1, 42) == 42
20+
def test_int_lo(self):
21+
assert clamp(1, 42, 200) == 42
22+
def test_int_normal(self):
23+
assert clamp(100, 42, 200) == 100
24+
def test_float_hi(self):
25+
assert clamp(0.942, 0.4, 0.9) == 0.9
26+
def test_float_lo(self):
27+
assert clamp(0.1, 0.42, 0.9) == 0.42
28+
def test_float_normal(self):
29+
assert clamp(0.42, 0.1, 0.9) == 0.42
30+
31+
32+
class Test_scale_num:
33+
def test_inrange(self):
34+
assert scale_num(13.1, 12.2, 15.3, -42.42, 42.42) == -17.789032258064516
35+
def test_outrange_lo(self):
36+
assert scale_num(13.1, 14.2, 15.3, -42.42, 42.42) == -127.25999999999986
37+
def test_outrange_hi(self):
38+
assert scale_num(16.1, 14.2, 15.3, -42.42, 42.42) == 104.12181818181817
39+
40+
41+
class Test_scale_array:
42+
def test_positive(self):
43+
assert scale_array(np.array([1, 2, 3]), 0.1, 0.3).all() == np.array([0.1, 0.2, 0.3]).all()
44+
def test_negative(self):
45+
assert scale_array(np.array([1, 2, 3]), -0.1, -0.3).all() == np.array([-0.1, -0.2, -0.3]).all()
46+
47+
class Test_generate_outfilename:
48+
def test_increment_once(self):
49+
f = open('testfile.txt', 'w')
50+
f.close()
51+
assert os.path.basename(generate_outfilename("testfile.txt")) == "testfile_0.txt"
52+
os.remove("testfile.txt")
53+
def test_increment_twice(self):
54+
f = open('testfile.txt', 'w')
55+
f.close()
56+
f = open('testfile_0.txt', 'w')
57+
f.close()
58+
assert os.path.basename(generate_outfilename("testfile.txt")) == "testfile_1.txt"
59+
os.remove("testfile.txt")
60+
os.remove("testfile_0.txt")
61+
62+
63+
#%%

0 commit comments

Comments
 (0)