Skip to content

Commit 517bc5c

Browse files
committed
testing bounded_linear and fix
1 parent 0d5bedb commit 517bc5c

File tree

3 files changed

+30
-45
lines changed

3 files changed

+30
-45
lines changed

Showcase.ipynb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,6 @@
124124
" Publisher: Prentice Hall\n",
125125
" Pub. Date: June 07, 1993"
126126
]
127-
},
128-
{
129-
"cell_type": "code",
130-
"execution_count": 19,
131-
"metadata": {
132-
"collapsed": false
133-
},
134-
"outputs": [
135-
{
136-
"ename": "TypeError",
137-
"evalue": "linear() got an unexpected keyword argument 'm'",
138-
"output_type": "error",
139-
"traceback": [
140-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
141-
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
142-
"\u001b[0;32m<ipython-input-19-2adc44ca0e1a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mfuzzy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfunctions\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mlinear\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mlinear\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2e217\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"-inf\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
143-
"\u001b[0;31mTypeError\u001b[0m: linear() got an unexpected keyword argument 'm'"
144-
]
145-
}
146-
],
147-
"source": [
148-
"from fuzzy.functions import linear\n",
149-
"\n",
150-
"f= linear(m=2e217, b=float(\"-inf\"))"
151-
]
152127
}
153128
],
154129
"metadata": {

fuzzy/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def bounded_linear(low_bound, high_bound, core_m=1, unsupported_m=0):
177177
>>> f(4)
178178
1.0
179179
"""
180-
if high_bound <= low_bound:
181-
raise ValueError('high must not be less than low.')
180+
assert high_bound > low_bound, 'high must not be less than low.'
181+
assert core_m != unsupported_m, "core_m must differ from unsupported_m"
182182

183183
gradient = (core_m - unsupported_m) / (high_bound - low_bound)
184184

test_fuzzy_units.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from fuzzy import functions as fun
77

88
class Test_Functions(TestCase):
9-
@given(st.floats(allow_nan=False, allow_infinity=False))
9+
@given(st.floats(allow_nan=False))
1010
def test_noop(self, x):
1111
f = fun.noop()
1212
assert f(x) == x
@@ -19,15 +19,16 @@ def test_inv(self, x):
1919

2020
@given(st.floats(allow_nan=False, allow_infinity=False),
2121
st.floats(allow_nan=False, allow_infinity=False))
22-
def test_constant(self, c, r):
22+
def test_constant(self, x, c):
2323
f = fun.constant(c)
24-
assert f(r) == c
24+
assert f(x) == c
2525

2626

27-
@given(st.floats(min_value=0, max_value=1),
28-
st.floats(min_value=0, max_value=1),
29-
st.floats(allow_nan=False))
30-
def test_alpha(self, lower, upper, x):
27+
@given(st.floats(allow_nan=False),
28+
st.floats(min_value=0, max_value=1),
29+
st.floats(min_value=0, max_value=1),
30+
)
31+
def test_alpha(self, x, lower, upper):
3132
assume(lower < upper)
3233
f = fun.alpha(lower, upper, fun.noop())
3334
if x <= lower:
@@ -37,22 +38,31 @@ def test_alpha(self, lower, upper, x):
3738
else:
3839
assert f(x) == x
3940

40-
@given(st.floats(),
41-
st.floats(min_value=0, max_value=1),
42-
st.floats(min_value=0, max_value=1),
41+
@given(st.floats(),
4342
st.floats(),
44-
45-
)
46-
def test_singleton(self, p, non_p_m, p_m, x):
43+
st.floats(min_value=0, max_value=1),
44+
st.floats(min_value=0, max_value=1))
45+
def test_singleton(self, x, p, non_p_m, p_m):
4746
assume(0 <= non_p_m <= 1)
4847
assume(0 <= p_m <= 1)
4948
f = fun.singleton(p, non_p_m, p_m)
5049
assert f(x) == (p_m if x == p else non_p_m)
5150

5251

53-
@given(st.floats(allow_nan=False),
54-
st.floats(allow_nan=False),
55-
st.floats(allow_nan=False))
56-
def test_linear(self, m, b, x):
52+
@given(st.floats(allow_nan=False, allow_infinity=False),
53+
st.floats(allow_nan=False, allow_infinity=False),
54+
st.floats(allow_nan=False, allow_infinity=False))
55+
def test_linear(self, x, m, b):
5756
f = fun.linear(m, b)
58-
assert 0 <= f(x) <= 1
57+
assert (0 <= f(x) <= 1)
58+
59+
@given(st.floats(allow_nan=False),
60+
st.floats(allow_nan=False, allow_infinity=False),
61+
st.floats(allow_nan=False, allow_infinity=False),
62+
st.floats(min_value=0, max_value=1),
63+
st.floats(min_value=0, max_value=1))
64+
def test_bounded_linear(self, x, low_bound, high_bound, core_m, unsupported_m):
65+
assume(low_bound < high_bound)
66+
assume(core_m != unsupported_m)
67+
f = fun.bounded_linear(low_bound, high_bound, core_m, unsupported_m)
68+
assert (0 <= f(x) <= 1)

0 commit comments

Comments
 (0)