def test_partition(): """Various unittests of partition.""" # partitioning by 1 generates singletons. assert list(u.partition([1, 2, 3, 4, 5], 1)) == [[1], [2], [3], [4], [5]] # partition works into groups of 2 assert list(u.partition([1, 2, 3, 4], 2)) == [[1, 2], [2, 3], [3, 4]] # >= case assert list(u.partition([1, 2, 3], 3)), [[1, 2, 3]] assert list(u.partition([1, 2, 3], 10)) == [[1, 2, 3]]
def test_partition(self): """Various unittests of partition.""" # partitioning by 1 generates singletons. self.assertListEqual(list(u.partition([1, 2, 3, 4, 5], 1)), [[1], [2], [3], [4], [5]]) # partition works into groups of 2 self.assertListEqual(list(u.partition([1, 2, 3, 4], 2)), [[1, 2], [2, 3], [3, 4]]) # >= case self.assertListEqual(list(u.partition([1, 2, 3], 3)), [[1, 2, 3]]) self.assertListEqual(list(u.partition([1, 2, 3], 10)), [[1, 2, 3]])
def script_args_to_labels(script_args: Optional[List[str]]) -> Dict[str, str]: """Converts the arguments supplied to our scripts into a dictionary usable as labels valid for Cloud submission. """ ret = {} def process_pair(k, v): if ua.is_key(k): clean_k = key_label(k) if clean_k != "": ret[clean_k] = "" if ua.is_key(v) else value_label(v) if script_args is None or len(script_args) == 0: return ret elif len(script_args) == 1: process_pair(script_args[0], None) # Handle the case where the final argument in the list is a boolean flag. # This won't get picked up by partition. elif len(script_args) > 1: for k, v in u.partition(script_args, 2): process_pair(k, v) process_pair(script_args[-1], None) return ret
def test_partition_by_big_gives_singleton(self, xs, n): """partitioning by a number >= the list length returns a singleton containing just the list. """ one_entry = list(u.partition(xs, len(xs) + n)) self.assertListEqual(one_entry, [xs])
def test_partition_by_one_gives_singletons(self, xs): """Partition by 1 gives a list of singletons.""" singletons = list(u.partition(xs, 1)) self.assertListEqual(singletons, [[x] for x in xs])
def test_partition_first_items(self, xs): """retrieving the first item of each grouping recovers the original list.""" rt = list(map(lambda pair: pair[0], u.partition(xs, 1))) self.assertListEqual(rt, xs)
def test_partition_by_one_gives_singletons(xs): """Partition by 1 gives a list of singletons.""" singletons = list(u.partition(xs, 1)) assert singletons == [[x] for x in xs]
def test_partition_first_items(xs): """retrieving the first item of each grouping recovers the original list.""" rt = list(map(lambda pair: pair[0], u.partition(xs, 1))) assert rt == xs