def test_unpacking_behavior(self): data = [(1, 2), (1, 4), (1, 8)] function = lambda x, y: x / y # <- function takes 2 args result = _map_data(function, Result(data, list)) self.assertIsInstance(result, Result) self.assertEqual(result.evaluation_type, list) self.assertEqual(result.fetch(), [0.5, 0.25, 0.125]) function = lambda z: z[0] / z[1] # <- function takes 1 arg result = _map_data(function, Result(data, list)) self.assertIsInstance(result, Result) self.assertEqual(result.evaluation_type, list) self.assertEqual(result.fetch(), [0.5, 0.25, 0.125])
def test_dataiter_dict_of_ints(self): iterable = Result({'a': 2, 'b': 3}, dict) function = lambda x: x * 2 result = _map_data(function, iterable) self.assertIsInstance(result, Result) self.assertEqual(result.evaluation_type, dict) self.assertEqual(result.fetch(), {'a': 4, 'b': 6})
def test_dataiter_dict_of_containers(self): iterable = Result({'a': [1, 2], 'b': (3, 4)}, dict) function = lambda x: x * 2 result = _map_data(function, iterable) self.assertIsInstance(result, Result) self.assertEqual(result.evaluation_type, dict) self.assertEqual(result.fetch(), {'a': [2, 4], 'b': (6, 8)})
def test_settype_to_list(self): iterable = Result([1, 2, 3], set) # <- Starts as 'set'. function = lambda x: x % 2 result = _map_data(function, iterable) self.assertIsInstance(result, Result) self.assertEqual(result.evaluation_type, list) # <- Now a 'list'. self.assertEqual(result.fetch(), [1, 0, 1])
def test_dataiter_list(self): iterable = Result([1, 2, 3], list) function = lambda x: x * 2 result = _map_data(function, iterable) self.assertIsInstance(result, Result) self.assertEqual(result.evaluation_type, list) self.assertEqual(result.fetch(), [2, 4, 6])
def test_single_int(self): function = lambda x: x * 2 result = _map_data(function, 3) self.assertEqual(result, 6)