@@ -904,7 +904,7 @@ def testTimeMovingCountUniqueRight(self):
904
904
window = 60
905
905
mat = TimeMovingCountUnique (window , Latest ("x" ), "right" )
906
906
values = np .random .randint (0 , 10 , 2500 )
907
- stamps = np .cumsum (np .random .randint (0 , 10 , 2500 ))
907
+ stamps = np .cumsum (np .random .randint (1 , 10 , 2500 ))
908
908
for i , (value , stamp ) in enumerate (zip (values , stamps )):
909
909
mat .push (dict (x = value , stamp = stamp ))
910
910
@@ -920,7 +920,7 @@ def testTimeMovingCountUniqueBoth(self):
920
920
window = 60
921
921
mat = TimeMovingCountUnique (window , Latest ("x" ), "both" )
922
922
values = np .random .randint (0 , 10 , 2500 )
923
- stamps = np .cumsum (np .random .randint (0 , 5 , 2500 ))
923
+ stamps = np .cumsum (np .random .randint (1 , 5 , 2500 ))
924
924
for i , (value , stamp ) in enumerate (zip (values , stamps )):
925
925
mat .push (dict (x = value , stamp = stamp ))
926
926
@@ -932,6 +932,38 @@ def testTimeMovingCountUniqueBoth(self):
932
932
"expected: {1}\n "
933
933
"calculated: {2}" .format (i , expected , calculated ))
934
934
935
+ def testTimeMovingCountUniqueLeft (self ):
936
+ window = 60
937
+ mat = TimeMovingCountUnique (window , Latest ("x" ), "left" )
938
+ values = np .random .randint (0 , 10 , 2500 )
939
+ stamps = np .cumsum (np .random .randint (1 , 5 , 2500 ))
940
+ for i , (value , stamp ) in enumerate (zip (values , stamps )):
941
+ mat .push (dict (x = value , stamp = stamp ))
942
+
943
+ calculated = mat .result ()
944
+ time_diff = (stamp - stamps ) <= window
945
+ time_diff [i :] = False
946
+ expected = len (np .unique (values [time_diff ]))
947
+ self .assertEqual (calculated , expected , "at index {0}\n "
948
+ "expected: {1}\n "
949
+ "calculated: {2}" .format (i , expected , calculated ))
950
+
951
+ def testTimeMovingCountUniqueNeither (self ):
952
+ window = 60
953
+ mat = TimeMovingCountUnique (window , Latest ("x" ), "neither" )
954
+ values = np .random .randint (0 , 10 , 2500 )
955
+ stamps = np .cumsum (np .random .randint (1 , 5 , 2500 ))
956
+ for i , (value , stamp ) in enumerate (zip (values , stamps )):
957
+ mat .push (dict (x = value , stamp = stamp ))
958
+
959
+ calculated = mat .result ()
960
+ time_diff = (stamp - stamps ) < window
961
+ time_diff [i :] = False
962
+ expected = len (np .unique (values [time_diff ]))
963
+ self .assertEqual (calculated , expected , "at index {0}\n "
964
+ "expected: {1}\n "
965
+ "calculated: {2}" .format (i , expected , calculated ))
966
+
935
967
def testMovingAllTrue (self ):
936
968
window = 3
937
969
underlying = Latest ('x' ) > 0.
0 commit comments