Esempio n. 1
0
 def test_group_by(self):
     linq = Linq(range(6))
     assert_equal(
         linq.group_by(lambda n: n % 2),
         IGroup([IPair(0, Linq([0, 2, 4])),
                 IPair(1, Linq([1, 3, 5]))]))
Esempio n. 2
0
 def test_eq(self):
     assert_equal(IPair(0, Linq([0, 1])), IPair(0, Linq([0, 1])))
Esempio n. 3
0
 def test_init3(self):
     IGroup([0, IPair(1, Linq([1, 2, 3]))])
Esempio n. 4
0
 def test_key(self):
     pair = IPair(0, Linq([1]))
     assert_equal(pair.key, 0)
Esempio n. 5
0
 def test_str(self):
     assert_equal(str(IPair(0, Linq([1]))), '{0: Linq<1>}')
Esempio n. 6
0
 def test_take_while_i2(self):
     linq = Linq(range(10)).concat(Linq(range(10)).reverse())
     assert_equal(linq.take_while_i(lambda i, x: i * x <= 100), linq)
Esempio n. 7
0
 def to_linq(self):
     """
     return ``Linq`` instance which consisted by elements of (key, value).
     """
     return Linq([(key, val) for key, val in self.items()])
Esempio n. 8
0
 def test_take_while3(self):
     assert_equal(Linq(range(10)).take_while(), Linq(range(10)))
Esempio n. 9
0
 def test_to_dict4(self):
     Linq(range(4)).to_dict(key_f=lambda _: 1)
Esempio n. 10
0
 def test_copy(self):
     linq = Linq(range(10))
     linq_copied = linq.copy()
     assert_true(linq is not linq_copied)
     assert_equal(linq, linq_copied)
Esempio n. 11
0
 def test_to_set(self):
     assert_equal(Linq([1, 1, 2, 3, 5]).to_set(), {1, 1, 2, 3, 5})
Esempio n. 12
0
 def test_to_list(self):
     assert_equal(Linq([1]).to_list(), [1])
     assert_equal(Linq([1, 1, 2, 3, 5]).to_list(), [1, 1, 2, 3, 5])
Esempio n. 13
0
 def test_take_while2(self):
     assert_equal(
         Linq(range(10)).take_while(lambda x: x < 100), Linq(range(10)))
Esempio n. 14
0
 def test_to_lookup3(self):
     assert_equal(
         Linq(range(10)).to_lookup(value_f=lambda n: n % 3),
         ILookup({
             0: Linq([0]),
             1: Linq([1]),
             2: Linq([2]),
             3: Linq([0]),
             4: Linq([1]),
             5: Linq([2]),
             6: Linq([0]),
             7: Linq([1]),
             8: Linq([2]),
             9: Linq([0])
         }))
Esempio n. 15
0
 def test_repr1(self):
     assert_equal(repr(Linq([1])), 'Linq<1>')
Esempio n. 16
0
 def test_add(self):
     linq1 = Linq([1, 2])
     linq2 = Linq([3, 4])
     linq = linq1 + linq2
     assert_is_instance(linq, Linq)
     assert_equal(linq.to_list(), [1, 2, 3, 4])
Esempio n. 17
0
 def test_repr2(self):
     assert_equal(repr(Linq([1, 2])), 'Linq<1, 2>')
Esempio n. 18
0
 def test_slice(self):
     linq = Linq(range(5))
     assert_true(linq[3] == 3)
Esempio n. 19
0
 def test_take_while_i3(self):
     linq = Linq(range(10)).concat(Linq(range(10)).reverse())
     assert_equal(linq.take_while_i(),
                  Linq(range(10)).concat(Linq(range(10)).reverse()))
Esempio n. 20
0
 def test_slice2(self):
     linq = Linq()
     assert_true(isinstance(linq[:], Linq))
     assert_true(linq[:] is not linq)
Esempio n. 21
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from ilinq.ilinq import Linq


def is_prime(n):
    if n < 2:
        return False

    for j in range(2, n):
        if n % j == 0:
            return False

    return True


if __name__ == '__main__':
    print(Linq(range(10**4)).last(is_prime))
    # => 9973
Esempio n. 22
0
 def test_str0(self):
     assert_equal(str(Linq([])), 'Linq<>')
Esempio n. 23
0
 def test_values(self):
     pair = IPair(0, Linq([1]))
     assert_equal(pair.values, Linq([1]))
Esempio n. 24
0
 def test_str1(self):
     assert_equal(str(Linq([1])), 'Linq<1>')
Esempio n. 25
0
 def test_repr(self):
     assert_equal(repr(IPair(0, Linq([1]))), 'IPair{0: Linq<1>}')
Esempio n. 26
0
 def test_str2(self):
     assert_equal(str(Linq([1, 2])), 'Linq<1, 2>')
Esempio n. 27
0
 def test_init2(self):
     IGroup([IPair(0, Linq([0, 1, 2]))])
Esempio n. 28
0
 def test_repr0(self):
     assert_equal(repr(Linq([])), 'Linq<>')
Esempio n. 29
0
 def test_init4(self):
     IGroup([
         IPair(0, Linq([1, 2, 3])),
         IPair(1, Linq([2, 3, 4])),
         IPair(1, Linq([2, 3, 4]))
     ])
Esempio n. 30
0
 def test_any4(self):
     linq = Linq([2, 3, 4, 5])
     assert_false(linq.any(cond_f=lambda x: x > 10))
     assert_false(linq.any(cond_f=lambda x: x > 10))