Skip to content

Commit 94e15b9

Browse files
committed
added tests to all functions, yet failing
1 parent 3492f7b commit 94e15b9

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

fuzzy/functions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,12 @@ def triangular(left, right, p=None, p_m=1, unsupported_m=0):
300300
p_m
301301
maximum membership-value, normal 1
302302
"""
303-
if left > right:
304-
raise ValueError('left must not be greater than right.')
303+
assert left < right, 'left must not be greater than right.'
304+
305305
p = p if p is not None else (left + right) / 2.
306-
if not(left <= p <= right):
307-
raise ValueError('p must be between left and right.')
306+
307+
assert left < p < right, "peak must be between left and right"
308+
308309
left_slope = bounded_linear(left, p, unsupported_m=0, core_m=p_m)
309310
right_slope = inv(bounded_linear(p, right, unsupported_m=0, core_m=p_m))
310311

test_fuzzy_units.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,68 @@ def test_S(self, x, left, right):
9191
st.floats(min_value=0, max_value=1),
9292
st.floats(min_value=0, max_value=1))
9393
def test_rectangular(self, x, low_bound, high_bound, core_m, unsupported_m):
94-
assume(left < right)
94+
assume(low_bound < high_bound)
9595
f = fun.rectangular(low_bound, high_bound, core_m, unsupported_m)
96+
assert (0 <= f(x) <= 1)
97+
98+
@given(st.floats(allow_nan=False),
99+
st.floats(allow_nan=False, allow_infinity=False),
100+
st.floats(allow_nan=False, allow_infinity=False),
101+
st.floats(allow_nan=False, allow_infinity=False),
102+
st.floats(min_value=0, max_value=1),
103+
st.floats(min_value=0, max_value=1))
104+
def test_triangular(self, x, left, right, p, p_m, unsupported_m):
105+
assume(left < p < right)
106+
f = fun.triangular(left, right, p, p_m, unsupported_m)
107+
assert (0 <= f(x) <= 1)
108+
109+
@given(st.floats(allow_nan=False),
110+
st.floats(allow_nan=False, allow_infinity=False),
111+
st.floats(allow_nan=False, allow_infinity=False),
112+
st.floats(allow_nan=False, allow_infinity=False),
113+
st.floats(min_value=0, max_value=1),
114+
st.floats(min_value=0, max_value=1))
115+
def test_trapezoid(self, x, left, c_left, c_right, right, c_m, unsupported_m):
116+
assume(left < right)
117+
f = fun.trapezoid(left, c_left, c_right, right, c_m, unsupported_m)
118+
assert (0 <= f(x) <= 1)
119+
120+
@given(st.floats(allow_nan=False),
121+
st.floats(min_value=0, max_value=1),
122+
st.floats(allow_nan=False, allow_infinity=False),
123+
st.floats(min_value=0, max_value=1))
124+
def test_sigmoid(self, x, L, k, x0):
125+
f = sigmoid(L, k, x0)
126+
assert (0 <= f(x) <= 1)
127+
128+
@given(st.floats(allow_nan=False),
129+
st.floats(allow_nan=False, allow_infinity=False),
130+
st.floats(allow_nan=False, allow_infinity=False))
131+
def test_bounded_sigmoid(self, x, low, high):
132+
assume(low < high)
133+
f = bounded_sigmoid(low, high)
134+
assert (0 <= f(x) <= 1)
135+
136+
@given(st.floats(allow_nan=False),
137+
st.floats(allow_nan=False, allow_infinity=False))
138+
def test_simple_sigmoid(self, x, k):
139+
f = fun.simple_sigmoid(k)
140+
assert (0 <= f(x) <= 1)
141+
142+
@given(st.floats(allow_nan=False),
143+
st.floats(allow_nan=False, allow_infinity=False),
144+
st.floats(allow_nan=False, allow_infinity=False),
145+
st.floats(allow_nan=False, allow_infinity=False))
146+
def test_triangular_sigmoid(self, x, left, right, p):
147+
assume(left < p < right)
148+
f = fun.bounded_sigmoid(left, right)
149+
assert (0 <= f(x) <= 1)
150+
151+
@given(st.floats(allow_nan=False),
152+
st.floats(allow_nan=False, allow_infinity=False),
153+
st.floats(allow_nan=False, allow_infinity=False),
154+
st.floats(allow_nan=False, allow_infinity=False))
155+
def test_gauss(self, x, b, p, p_m):
156+
assume(left < p < right)
157+
f = fun.gauss(left, right)
96158
assert (0 <= f(x) <= 1)

0 commit comments

Comments
 (0)