33Functional test of the fuzzylogic lib 'fuzzy'.
44"""
55
6- import unittest
6+ from unittest import TestCase , skip
77
8- from fuzzy .classes import Domain , Set , Rule
9- from fuzzy .functions import R , S
8+ from fuzzy .classes import Domain , Set
9+ from fuzzy .rules import scale
10+ from fuzzy .functions import R , S , bounded_linear
1011
11- class TestTop (unittest . TestCase ):
12+ class TestTop (TestCase ):
1213 def setUp (self ):
13- """
14- Lucy tells her robot that it is good to heat when it's cold and not when it's hot."""
14+ """Lucy tells her robot that it is good to heat when it's cold and not when it's hot."""
1515 self .temp = Domain ('temperature' , - 100 , 100 ) # in Celsius
1616 self .temp .cold = Set (S (0 , 15 ))
1717 self .temp .hot = Set (R (10 , 30 ))
1818 self .temp .warm = ~ self .temp .cold & ~ self .temp .hot
1919
2020 def test_temp (self ):
2121 assert (self .temp (6 ) == {'cold' : 0.6 , 'hot' : 0 , 'warm' : 0.4 })
22+
23+ class Test_Meal (TestCase ):
24+ def setUp (self ):
25+ """Tom is surveying restaurants.
26+ He doesn't need fancy logic but rather uses a simple approach with weights.
27+ He went into a small, dirty bar that served some delicious drink and food.
28+ """
29+ self .R = Domain ("rating" , 1 , 10 , res = 0.1 )
30+ self .R .norm = Set (bounded_linear (1 , 10 ))
31+ self .weights = weights = {"beverage" : 0.3 ,
32+ "atmosphere" : 0.2 ,
33+ "arrangement" :0.2 ,
34+ "taste" : 0.3 }
35+ self .ratings = {"beverage" : self .R .MIN (7 ),
36+ "atmosphere" : self .R .MIN (3 ),
37+ "arrangement" : self .R .MIN (2 ),
38+ "taste" : self .R .MIN (9 )}
2239
2340if __name__ == '__main__' :
2441 unittest .main ()
0 commit comments