def test_left_floor_and_ceiling(self): iterable = [4,5,1,2,3,6] expected = [ (None, None) # 4 , (0 , None) # 5 , (None, 0 ) # 1 , (2 , 0 ) # 2 , (3 , 0 ) # 3 , (1 , None) # 6 ] index = 0 for fac in left_floor_and_ceiling(iterable): self.assertEqual(fac, expected[index]) index += 1 iterable = [4,1,2,5,3] expected = [ (-1 , 5 ) # 4 , (-1 , 0 ) # 1 , (1 , 0 ) # 2 , (0 , 5 ) # 5 , (2 , 0 ) # 3 ] index = 0 for fac in left_floor_and_ceiling(iterable, default_floor=-1, default_ceiling=5): self.assertEqual(fac, expected[index]) index += 1 iterable = [1,2,3] expected = [ (None, None) # 1 , (0 , None) # 2 , (1 , None) # 3 ] index = 0 for fac in left_floor_and_ceiling(iterable): self.assertEqual(fac, expected[index]) index += 1 iterable = [3,2,1] expected = [ (None, None) # 3 , (None, 0 ) # 2 , (None, 1 ) # 1 ] index = 0 for fac in left_floor_and_ceiling(iterable): self.assertEqual(fac, expected[index]) index += 1
def _pattern_details(self): """Subroutine of occurrences_in method.""" # If details have been calculated before, return cached result if self._cached_pattern_details is not None: return self._cached_pattern_details result = [] index = 0 for fac_indices in left_floor_and_ceiling(self): base_element = self[index] compiled = (fac_indices.floor, fac_indices.ceiling, self[index] if fac_indices.floor is None else base_element - self[fac_indices.floor], len(self) - self[index] if fac_indices.ceiling is None else self[fac_indices.ceiling] - base_element, ) result.append(compiled) index += 1 self._cached_pattern_details = result return result