Skip to content

Commit 814b7fd

Browse files
committed
chore: removed import-boilerplate in favor of pip -e
1 parent b21afd5 commit 814b7fd

File tree

3 files changed

+106
-125
lines changed

3 files changed

+106
-125
lines changed

tests/test_caro.py

+50-56
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,50 @@
1-
import sys
2-
from pathlib import Path
3-
4-
src = str((Path(__file__).parent / "../src").resolve())
5-
sys.path.insert(0, src)
6-
7-
import numpy as np
8-
from fuzzylogic.classes import Domain, Rule
9-
from fuzzylogic.functions import R, S, trapezoid
10-
11-
temp = Domain("Temperatur", -30, 100, res=0.0001) # ,res=0.1)
12-
temp.kalt = S(-10, 30)
13-
temp.heiß = R(30, 70)
14-
temp.mittel = ~temp.heiß & ~temp.kalt
15-
16-
17-
tan = Domain("tandelta", 0, 1.3, res=0.0001) # ,res=0.1)
18-
tan.klein = S(0.1, 0.5)
19-
tan.groß = R(0.5, 0.9)
20-
tan.mittel = ~tan.groß & ~tan.klein
21-
22-
gef = Domain("Gefahrenbewertung", -0.5, 1.5, res=0.0001) # ,res=0.1)
23-
gef.klein = trapezoid(-0.5, 0, 0, 0.5)
24-
gef.groß = trapezoid(0.5, 1, 1, 1.5)
25-
gef.mittel = trapezoid(0, 0.5, 0.5, 1)
26-
27-
R1 = Rule({(temp.kalt, tan.klein): gef.klein})
28-
R2 = Rule({(temp.mittel, tan.klein): gef.klein})
29-
R3 = Rule({(temp.heiß, tan.klein): gef.klein})
30-
R4 = Rule({(temp.kalt, tan.mittel): gef.klein})
31-
R5 = Rule({(temp.mittel, tan.mittel): gef.mittel})
32-
R6 = Rule({(temp.heiß, tan.mittel): gef.groß})
33-
R7 = Rule({(temp.kalt, tan.groß): gef.mittel})
34-
R8 = Rule({(temp.mittel, tan.groß): gef.groß})
35-
R9 = Rule({(temp.heiß, tan.groß): gef.groß})
36-
37-
38-
rules = R1 | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9
39-
40-
table = """
41-
tan.klein tan.mittel tan.groß
42-
temp.kalt gef.klein gef.klein gef.mittel
43-
temp.mittel gef.klein gef.mittel gef.groß
44-
temp.heiß gef.klein gef.groß gef.groß
45-
"""
46-
47-
from fuzzylogic.classes import rule_from_table
48-
49-
table_rules = rule_from_table(table, globals())
50-
51-
assert table_rules == rules
52-
53-
value = {temp: 20, tan: 0.55}
54-
result = rules(value)
55-
assert isinstance(result, float)
56-
assert np.isclose(result, 0.45, atol=0.0001)
1+
import numpy as np
2+
from fuzzylogic.classes import Domain, Rule
3+
from fuzzylogic.functions import R, S, trapezoid
4+
5+
temp = Domain("Temperatur", -30, 100, res=0.0001) # ,res=0.1)
6+
temp.kalt = S(-10, 30)
7+
temp.heiß = R(30, 70)
8+
temp.mittel = ~temp.heiß & ~temp.kalt
9+
10+
11+
tan = Domain("tandelta", 0, 1.3, res=0.0001) # ,res=0.1)
12+
tan.klein = S(0.1, 0.5)
13+
tan.groß = R(0.5, 0.9)
14+
tan.mittel = ~tan.groß & ~tan.klein
15+
16+
gef = Domain("Gefahrenbewertung", -0.5, 1.5, res=0.0001) # ,res=0.1)
17+
gef.klein = trapezoid(-0.5, 0, 0, 0.5)
18+
gef.groß = trapezoid(0.5, 1, 1, 1.5)
19+
gef.mittel = trapezoid(0, 0.5, 0.5, 1)
20+
21+
R1 = Rule({(temp.kalt, tan.klein): gef.klein})
22+
R2 = Rule({(temp.mittel, tan.klein): gef.klein})
23+
R3 = Rule({(temp.heiß, tan.klein): gef.klein})
24+
R4 = Rule({(temp.kalt, tan.mittel): gef.klein})
25+
R5 = Rule({(temp.mittel, tan.mittel): gef.mittel})
26+
R6 = Rule({(temp.heiß, tan.mittel): gef.groß})
27+
R7 = Rule({(temp.kalt, tan.groß): gef.mittel})
28+
R8 = Rule({(temp.mittel, tan.groß): gef.groß})
29+
R9 = Rule({(temp.heiß, tan.groß): gef.groß})
30+
31+
32+
rules = R1 | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9
33+
34+
table = """
35+
tan.klein tan.mittel tan.groß
36+
temp.kalt gef.klein gef.klein gef.mittel
37+
temp.mittel gef.klein gef.mittel gef.groß
38+
temp.heiß gef.klein gef.groß gef.groß
39+
"""
40+
41+
from fuzzylogic.classes import rule_from_table
42+
43+
table_rules = rule_from_table(table, globals())
44+
45+
assert table_rules == rules
46+
47+
value = {temp: 20, tan: 0.55}
48+
result = rules(value)
49+
assert isinstance(result, float)
50+
assert np.isclose(result, 0.45, atol=0.0001)

tests/test_functionality.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
"""
2-
Functional test of the fuzzylogic lib 'fuzzy'.
2+
Functional tests of the fuzzylogic library.
33
"""
44

5-
import os
6-
import sys
7-
8-
here = os.path.split(os.path.abspath(os.path.dirname(__file__)))
9-
src = os.path.join(here[0], "src")
10-
sys.path.insert(0, src)
11-
print(sys.path)
12-
135
import unittest
146

7+
from numpy import array_equal
8+
from pytest import fixture
9+
1510
from fuzzylogic.classes import Domain, Set
1611
from fuzzylogic.functions import R, S, bounded_linear
17-
from fuzzylogic.rules import rescale, weighted_sum
18-
from numpy import array_equal
19-
from pytest import fixture, raises
12+
from fuzzylogic.rules import weighted_sum
2013

2114

2215
@fixture
@@ -39,9 +32,7 @@ def simple():
3932
def test_array(simple):
4033
assert array_equal(simple.low.array(), [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
4134
assert array_equal(simple.high.array(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 1.0])
42-
assert (
43-
len(simple.low.array()) == 11
44-
) # unlike arrays and lists, upper boundary is INCLUDED
35+
assert len(simple.low.array()) == 11 # unlike arrays and lists, upper boundary is INCLUDED
4536

4637

4738
def test_value(temp):

0 commit comments

Comments
 (0)