Skip to content

Commit 4d443fc

Browse files
committed
set complement test
1 parent f7f9db5 commit 4d443fc

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

Showcase.ipynb

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,61 @@
134134
},
135135
{
136136
"cell_type": "code",
137-
"execution_count": 3,
137+
"execution_count": 28,
138138
"metadata": {
139139
"collapsed": false
140140
},
141-
"outputs": [],
141+
"outputs": [
142+
{
143+
"data": {
144+
"text/plain": [
145+
"<function all>"
146+
]
147+
},
148+
"execution_count": 28,
149+
"metadata": {},
150+
"output_type": "execute_result"
151+
}
152+
],
142153
"source": [
143154
"%matplotlib inline\n",
144155
"\n",
145156
"from fuzzy.classes import Domain, Set, Rule\n",
146157
"from fuzzy.functions import alpha, triangular, gauss, R, S\n",
158+
"import fuzzy.functions as fun\n",
147159
"from fuzzy.hedges import plus, minus, very\n",
148160
"\n",
149161
"IN = Domain(\"numbers in\", 0, 10, res=0.1)\n",
150162
"IN.close_5 = Set(triangular(2, 10, c=5))\n",
151-
"OUT = Domain(\"numbers out\", 100, 200)"
163+
"OUT = Domain(\"numbers out\", 100, 200)\n",
164+
"\n",
165+
"D = Domain(\"d\", 0, 10, res=0.1)\n",
166+
"D.s1 = Set(fun.bounded_linear(3, 12))\n",
167+
"D.s2 = ~~D.s1\n",
168+
"all(isclose(D.s1.array(), D.s2.array()))"
152169
]
153170
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": 8,
174+
"metadata": {
175+
"collapsed": false
176+
},
177+
"outputs": [
178+
{
179+
"ename": "NameError",
180+
"evalue": "name 'fun' is not defined",
181+
"output_type": "error",
182+
"traceback": [
183+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
184+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
185+
"\u001b[0;32m<ipython-input-8-cd1aace75fdc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mD\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDomain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"d\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mres\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mD\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0ms1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfun\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbounded_linear\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m12\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mD\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0ms2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m~\u001b[0m\u001b[0;34m~\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
186+
"\u001b[0;31mNameError\u001b[0m: name 'fun' is not defined"
187+
]
188+
}
189+
],
190+
"source": []
191+
},
154192
{
155193
"cell_type": "code",
156194
"execution_count": 4,

test_fuzzy_units.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from hypothesis import given, strategies as st, assume
33
from math import isclose
44
from unittest import TestCase, skip
5+
import numpy as np
56

67
from fuzzy.classes import Domain, Set, Rule
78
from fuzzy import functions as fun
@@ -313,4 +314,10 @@ def test_sub_super_set(self):
313314
D.s = Set(fun.bounded_linear(3, 12))
314315
x = D.s.normalized()
315316
assert (x >= D.s)
316-
assert (D.s <= x)
317+
assert (D.s <= x)
318+
319+
def test_complement(self):
320+
D = Domain("d", 0, 10, res=0.1)
321+
D.s1 = Set(fun.bounded_linear(3, 12))
322+
D.s2 = ~~D.s1
323+
assert all(np.isclose(D.s1.array(), D.s2.array()))

0 commit comments

Comments
 (0)