예제 #1
0
 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)
예제 #2
0
 def test_last_dict_empty(self):
     d = dict()
     e = Enumerable(d)
     result = e.last()
     self.assertIsNone(result)
예제 #3
0
 def test_last_range_no_predicate(self):
     e = Enumerable(range(10))
     result = e.last()
     self.assertEqual(result, 9)
예제 #4
0
 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)
예제 #5
0
 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')
예제 #6
0
 def test_all_empty(self):
     e = Enumerable.empty()
     result = e.all(lambda x: False)
     self.assertTrue(result)
예제 #7
0
 def test_last_range_predicate_exists(self):
     e = Enumerable(range(10))
     result = e.last(lambda x: x < 6)
     self.assertEqual(result, 5)
예제 #8
0
 def test_any_dict_empty(self):
     d = dict()
     e = Enumerable(d)
     result = e.any(lambda x: True)
     self.assertFalse(result)
예제 #9
0
 def test_any_empty(self):
     e = Enumerable.empty()
     result = e.any(lambda x: False)
     self.assertFalse(result)
예제 #10
0
 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)
예제 #11
0
 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)
예제 #12
0
 def test_any_range_predicate_not_exists(self):
     e = Enumerable(range(10))
     result = e.any(lambda x: x > 100)
     self.assertFalse(result)
예제 #13
0
 def test_take_empty(self):
     e = Enumerable.empty()
     result = list(e.take(3))
     expected_result = []
     self.assertListEqual(result, expected_result)
예제 #14
0
 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)
예제 #15
0
 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)
예제 #16
0
 def test_any_range_some_true(self):
     e = Enumerable(range(10))
     result = e.any(lambda x: x == 9)
     self.assertTrue(result)
예제 #17
0
 def test_all_dict_empty(self):
     d = dict()
     e = Enumerable(d)
     result = e.all(lambda x: True)
     self.assertTrue(result)
예제 #18
0
 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})
예제 #19
0
 def test_all_range_some_false(self):
     e = Enumerable(range(10))
     result = e.all(lambda x: x < 9)
     self.assertFalse(result)
예제 #20
0
 def test_select_empty_list(self):
     e = Enumerable([])
     result = e.select(lambda x: 'hello').to_list()
     self.assertListEqual(result, [])
예제 #21
0
 def test_last_range_predicate_no_match(self):
     e = Enumerable(range(10))
     result = e.last(lambda x: x == 'hello')
     self.assertIsNone(result)
예제 #22
0
 def test_select_empty(self):
     e = Enumerable.empty()
     result = e.select(lambda x: x / 3).to_list()
     self.assertListEqual(result, [])
예제 #23
0
 def test_last_dict_no_predicate(self):
     d = {'a': 1, 'b': 2}
     e = Enumerable(d)
     result = e.last()
     self.assertIn(result, d.keys())
예제 #24
0
 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])
예제 #25
0
 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)
예제 #26
0
 def test_all_range_all_true(self):
     e = Enumerable(range(10))
     result = e.all(lambda x: x < 100)
     self.assertTrue(result)
예제 #27
0
 def test_last_empty_no_predicate(self):
     e = Enumerable.empty()
     result = e.last()
     self.assertIsNone(result)
예제 #28
0
 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)
예제 #29
0
 def test_last_empty_predicate(self):
     e = Enumerable.empty()
     result = e.last(lambda x: len(x))
     self.assertIsNone(result)
예제 #30
0
 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)