Skip to content

Commit bef19bb

Browse files
committed
testing, removed cache/
1 parent c6d0026 commit bef19bb

File tree

6 files changed

+113
-55
lines changed

6 files changed

+113
-55
lines changed

.cache/v/cache/lastfailed

Lines changed: 0 additions & 1 deletion
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.hypothesis
2-
.cache
2+
.cache/*
33
__pycache__
44
.ipynb_checkpoints/
55
_config.yml
6+
DEV*

Showcase.ipynb

Lines changed: 46 additions & 8 deletions
Large diffs are not rendered by default.

TODO-fuzzy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ do: #Set.plot SHOULD always plot the full set range
88
---
99
do: MUST fix #Domain._sets (should be either set OR dict)
1010
until: 2017-3-1
11+
requires: Set.plot testcase
1112
---
1213
do: check tests
13-
every: day
14+
after: 2017-3-1
15+
repeat: dayly
16+
until: end of year
1417
---
15-
do: SHOULD find examples for truth functions
18+
do: SHOULD find examples for truth functions
19+
---

fuzzy/functions.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,11 @@ def f(x):
109109
return f
110110

111111

112-
def linear(a=0, b=0):
112+
def linear(m:float=0, b:float=0) -> callable:
113113
"""A textbook linear function with y-axis section and gradient.
114-
f(x) = a*x + b
114+
f(x) = m*x + b
115115
BUT CLIPPED.
116116
117-
variables
118-
--------
119-
b: float
120-
y-axis section for f(0)
121-
a: float
122-
gradient - if a == 0, the function is constant
123-
124117
>>> f = linear(1, -1)
125118
>>> f(-2) # should be -3 but clipped
126119
0
@@ -135,13 +128,14 @@ def linear(a=0, b=0):
135128
>>> f(3) # should be 2 but clipped
136129
1
137130
"""
138-
def f(x):
139-
m = a * x + b
140-
if m < 0:
131+
def f(x) -> float:
132+
y = m * x + b
133+
if y <= 0:
141134
return 0
142-
if m > 1:
135+
elif y >= 1:
143136
return 1
144-
return m
137+
else:
138+
return y
145139
return f
146140

147141

test_fuzzy_units.py

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
11

22
from hypothesis import given, strategies as st, assume
33
from math import isclose
4+
from unittest import TestCase
45

56
from fuzzy import functions as fun
6-
7-
@given(st.floats(allow_nan=False, allow_infinity=False))
8-
def test_noop(x):
9-
f = fun.noop()
10-
assert f(x) == x
11-
12-
@given(st.floats(allow_nan=False, allow_infinity=False))
13-
def test_inv(x):
14-
assume(0 <= x <= 1)
15-
f = fun.inv(fun.noop())
16-
assert isclose(f(f(x)), x, abs_tol=1e-16)
17-
18-
@given(st.floats(allow_nan=False, allow_infinity=False),
19-
st.floats(allow_nan=False, allow_infinity=False))
20-
def test_constant(c, r):
21-
f = fun.constant(c)
22-
assert f(r) == c
237

8+
class Test_Functions(TestCase):
9+
@given(st.floats(allow_nan=False, allow_infinity=False))
10+
def test_noop(self, x):
11+
f = fun.noop()
12+
assert f(x) == x
13+
14+
@given(st.floats(allow_nan=False, allow_infinity=False))
15+
def test_inv(self, x):
16+
assume(0 <= x <= 1)
17+
f = fun.inv(fun.noop())
18+
assert isclose(f(f(x)), x, abs_tol=1e-16)
19+
20+
@given(st.floats(allow_nan=False, allow_infinity=False),
21+
st.floats(allow_nan=False, allow_infinity=False))
22+
def test_constant(self, c, r):
23+
f = fun.constant(c)
24+
assert f(r) == c
25+
26+
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):
31+
assume(lower < upper)
32+
f = fun.alpha(lower, upper, fun.noop())
33+
if x <= lower:
34+
assert f(x) == lower
35+
elif x >= upper:
36+
assert f(x) == upper
37+
else:
38+
assert f(x) == x
39+
40+
@given(st.floats(),
41+
st.floats(min_value=0, max_value=1),
42+
st.floats(min_value=0, max_value=1),
43+
st.floats(),
44+
45+
)
46+
def test_singleton(self, p, non_p_m, p_m, x):
47+
assume(0 <= non_p_m <= 1)
48+
assume(0 <= p_m <= 1)
49+
f = fun.singleton(p, non_p_m, p_m)
50+
assert f(x) == (p_m if x == p else non_p_m)
51+
2452

25-
@given(st.floats(min_value=0, max_value=1),
26-
st.floats(min_value=0, max_value=1),
27-
st.floats(allow_nan=False))
28-
def test_alpha(lower, upper, x):
29-
assume(lower < upper)
30-
f = fun.alpha(lower, upper, fun.noop())
31-
if x <= lower:
32-
assert f(x) == lower
33-
elif x >= upper:
34-
assert f(x) == upper
35-
else:
36-
assert f(x) == x
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):
57+
f = fun.linear(m, b)
58+
assert 0 <= f(x) <= 1

0 commit comments

Comments
 (0)