@@ -2963,6 +2963,30 @@ def test_evaluate_equal_dim_and_num_lt(self):
2963
2963
2964
2964
2965
2965
#*****************************************************************
2966
+
2967
+ def test_contiguous_regions ():
2968
+ a , b , c = 3 , 4 , 5
2969
+ # Starts and ends with True
2970
+ mask = [True ]* a + [False ]* b + [True ]* c
2971
+ expected = [(0 , a ), (a + b , a + b + c )]
2972
+ assert_equal (mlab .contiguous_regions (mask ), expected )
2973
+ d , e = 6 , 7
2974
+ # Starts with True ends with False
2975
+ mask = mask + [False ]* e
2976
+ assert_equal (mlab .contiguous_regions (mask ), expected )
2977
+ # Starts with False ends with True
2978
+ mask = [False ]* d + mask [:- e ]
2979
+ expected = [(d , d + a ), (d + a + b , d + a + b + c )]
2980
+ assert_equal (mlab .contiguous_regions (mask ), expected )
2981
+ # Starts and ends with False
2982
+ mask = mask + [False ]* e
2983
+ assert_equal (mlab .contiguous_regions (mask ), expected )
2984
+ # No True in mask
2985
+ assert_equal (mlab .contiguous_regions ([False ]* 5 ), [])
2986
+ # Empty mask
2987
+ assert_equal (mlab .contiguous_regions ([]), [])
2988
+
2989
+
2966
2990
#*****************************************************************
2967
2991
2968
2992
if __name__ == '__main__' :
0 commit comments