55from time import struct_time , mktime
66
77import numpy as np
8+
9+ from Orange .data import ContinuousVariable
810from Orange .preprocess .discretize import \
9- _time_binnings , time_binnings , BinDefinition
11+ _time_binnings , time_binnings , BinDefinition , Discretizer
1012
1113
1214# pylint: disable=redefined-builtin
@@ -17,12 +19,12 @@ def create(year=1970, month=1, day=1, hour=0, min=0, sec=0):
1719class TestTimeBinning (unittest .TestCase ):
1820 def setUp (self ):
1921 self .dates = [mktime (x ) for x in
20- [(1975 , 6 , 9 , 10 , 0 , 0 , 0 , 161 , 0 ),
21- (1975 , 6 , 9 , 10 , 50 , 0 , 0 , 161 , 0 ),
22- (1975 , 6 , 9 , 11 , 40 , 0 , 0 , 161 , 0 ),
23- (1975 , 6 , 9 , 12 , 30 , 0 , 0 , 161 , 0 ),
24- (1975 , 6 , 9 , 13 , 20 , 0 , 0 , 161 , 0 ),
25- (1975 , 6 , 9 , 14 , 10 , 0 , 0 , 161 , 0 )]]
22+ [(1975 , 6 , 9 , 10 , 0 , 0 , 0 , 161 , 0 ),
23+ (1975 , 6 , 9 , 10 , 50 , 0 , 0 , 161 , 0 ),
24+ (1975 , 6 , 9 , 11 , 40 , 0 , 0 , 161 , 0 ),
25+ (1975 , 6 , 9 , 12 , 30 , 0 , 0 , 161 , 0 ),
26+ (1975 , 6 , 9 , 13 , 20 , 0 , 0 , 161 , 0 ),
27+ (1975 , 6 , 9 , 14 , 10 , 0 , 0 , 161 , 0 )]]
2628
2729 def test_binning (self ):
2830 def tr1 (s ):
@@ -752,5 +754,28 @@ def test_thresholds(self):
752754 self .assertEqual (bindef .nbins , 2 )
753755
754756
757+ class TestDiscretizer (unittest .TestCase ):
758+ def test_equality (self ):
759+ v1 = ContinuousVariable ("x" )
760+ v2 = ContinuousVariable ("x" , number_of_decimals = 42 )
761+ v3 = ContinuousVariable ("y" )
762+ assert v1 == v2
763+
764+ t1 = Discretizer (v1 , [0 , 2 , 1 ])
765+ t1a = Discretizer (v2 , [0 , 2 , 1 ])
766+ t2 = Discretizer (v3 , [0 , 2 , 1 ])
767+ self .assertEqual (t1 , t1 )
768+ self .assertEqual (t1 , t1a )
769+ self .assertNotEqual (t1 , t2 )
770+
771+ self .assertEqual (hash (t1 ), hash (t1a ))
772+ self .assertNotEqual (hash (t1 ), hash (t2 ))
773+
774+ t1 = Discretizer (v1 , [0 , 2 , 1 ])
775+ t1a = Discretizer (v2 , [1 , 2 , 0 ])
776+ self .assertNotEqual (t1 , t1a )
777+ self .assertNotEqual (hash (t1 ), hash (t1a ))
778+
779+
755780if __name__ == '__main__' :
756781 unittest .main ()
0 commit comments