def test_take_dict_more_items(self): d = {'a': 1, 'b': 2, 'c': 3, 'd': 4} e = Enumerable(d) result = sorted(list(e.take(15))) expected_result = ['a', 'b', 'c', 'd'] self.assertListEqual(result, expected_result)
def test_last_dict_empty(self): d = dict() e = Enumerable(d) result = e.last() self.assertIsNone(result)
def test_last_range_no_predicate(self): e = Enumerable(range(10)) result = e.last() self.assertEqual(result, 9)
def test_last_range_predicate_no_match_default(self): e = Enumerable(range(10)) result = e.last(lambda x: x == 'hello', default=False) self.assertFalse(result)
def test_last_dict_predicate_exists(self): d = {'a': 1, 'b': 2} e = Enumerable(d) result = e.last(lambda x: x != 'a') self.assertEqual(result, 'b')
def test_all_empty(self): e = Enumerable.empty() result = e.all(lambda x: False) self.assertTrue(result)
def test_last_range_predicate_exists(self): e = Enumerable(range(10)) result = e.last(lambda x: x < 6) self.assertEqual(result, 5)
def test_any_dict_empty(self): d = dict() e = Enumerable(d) result = e.any(lambda x: True) self.assertFalse(result)
def test_any_empty(self): e = Enumerable.empty() result = e.any(lambda x: False) self.assertFalse(result)
def test_any_dict_predicate_exists(self): d = {'a': 1, 'b': 2} e = Enumerable(d) result = e.any(lambda x: x.isalpha()) self.assertTrue(result)
def test_any_dict_predicate_not_exists(self): d = {'a': 1, 'b': 2} e = Enumerable(d) result = e.any(lambda x: x.isdigit()) self.assertFalse(result)
def test_any_range_predicate_not_exists(self): e = Enumerable(range(10)) result = e.any(lambda x: x > 100) self.assertFalse(result)
def test_take_empty(self): e = Enumerable.empty() result = list(e.take(3)) expected_result = [] self.assertListEqual(result, expected_result)
def test_take_negative_number_of_items(self): l = [1, 2, 3, 'a'] e = Enumerable(l) result = list(e.take(-10)) expected_result = [] self.assertListEqual(result, expected_result)
def test_all_dict_all_true(self): d = {'a': 1, 'b': 2} e = Enumerable(d) result = e.all(lambda x: x.isalpha()) self.assertTrue(result)
def test_any_range_some_true(self): e = Enumerable(range(10)) result = e.any(lambda x: x == 9) self.assertTrue(result)
def test_all_dict_empty(self): d = dict() e = Enumerable(d) result = e.all(lambda x: True) self.assertTrue(result)
def test_select_to_dict(self): e = Enumerable(range(1, 4)) result = e.select(lambda x: 'a' * x).to_dict(lambda x: x, lambda x: len(x)) self.assertDictEqual(result, {'a': 1, 'aa': 2, 'aaa': 3})
def test_all_range_some_false(self): e = Enumerable(range(10)) result = e.all(lambda x: x < 9) self.assertFalse(result)
def test_select_empty_list(self): e = Enumerable([]) result = e.select(lambda x: 'hello').to_list() self.assertListEqual(result, [])
def test_last_range_predicate_no_match(self): e = Enumerable(range(10)) result = e.last(lambda x: x == 'hello') self.assertIsNone(result)
def test_select_empty(self): e = Enumerable.empty() result = e.select(lambda x: x / 3).to_list() self.assertListEqual(result, [])
def test_last_dict_no_predicate(self): d = {'a': 1, 'b': 2} e = Enumerable(d) result = e.last() self.assertIn(result, d.keys())
def test_select_to_list(self): e = Enumerable(range(5)) result = e.select(lambda x: x * 2).to_list() self.assertListEqual(result, [0, 2, 4, 6, 8])
def test_last_dict_predicate_not_exists(self): d = {'a': 1, 'b': 2} e = Enumerable(d) result = e.last(lambda x: x > 'z') self.assertIsNone(result)
def test_all_range_all_true(self): e = Enumerable(range(10)) result = e.all(lambda x: x < 100) self.assertTrue(result)
def test_last_empty_no_predicate(self): e = Enumerable.empty() result = e.last() self.assertIsNone(result)
def test_all_dict_all_false(self): d = {'a': 1, 'b': 2} e = Enumerable(d) result = e.all(lambda x: x > 'b') self.assertFalse(result)
def test_last_empty_predicate(self): e = Enumerable.empty() result = e.last(lambda x: len(x)) self.assertIsNone(result)
def test_take_range_some_items(self): e = Enumerable(range(10)) result = list(e.take(5)) expected_result = [0, 1, 2, 3, 4] self.assertListEqual(result, expected_result)