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]))]))
def test_eq(self): assert_equal(IPair(0, Linq([0, 1])), IPair(0, Linq([0, 1])))
def test_init3(self): IGroup([0, IPair(1, Linq([1, 2, 3]))])
def test_key(self): pair = IPair(0, Linq([1])) assert_equal(pair.key, 0)
def test_str(self): assert_equal(str(IPair(0, Linq([1]))), '{0: Linq<1>}')
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)
def to_linq(self): """ return ``Linq`` instance which consisted by elements of (key, value). """ return Linq([(key, val) for key, val in self.items()])
def test_take_while3(self): assert_equal(Linq(range(10)).take_while(), Linq(range(10)))
def test_to_dict4(self): Linq(range(4)).to_dict(key_f=lambda _: 1)
def test_copy(self): linq = Linq(range(10)) linq_copied = linq.copy() assert_true(linq is not linq_copied) assert_equal(linq, linq_copied)
def test_to_set(self): assert_equal(Linq([1, 1, 2, 3, 5]).to_set(), {1, 1, 2, 3, 5})
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])
def test_take_while2(self): assert_equal( Linq(range(10)).take_while(lambda x: x < 100), Linq(range(10)))
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]) }))
def test_repr1(self): assert_equal(repr(Linq([1])), 'Linq<1>')
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])
def test_repr2(self): assert_equal(repr(Linq([1, 2])), 'Linq<1, 2>')
def test_slice(self): linq = Linq(range(5)) assert_true(linq[3] == 3)
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()))
def test_slice2(self): linq = Linq() assert_true(isinstance(linq[:], Linq)) assert_true(linq[:] is not linq)
#!/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
def test_str0(self): assert_equal(str(Linq([])), 'Linq<>')
def test_values(self): pair = IPair(0, Linq([1])) assert_equal(pair.values, Linq([1]))
def test_str1(self): assert_equal(str(Linq([1])), 'Linq<1>')
def test_repr(self): assert_equal(repr(IPair(0, Linq([1]))), 'IPair{0: Linq<1>}')
def test_str2(self): assert_equal(str(Linq([1, 2])), 'Linq<1, 2>')
def test_init2(self): IGroup([IPair(0, Linq([0, 1, 2]))])
def test_repr0(self): assert_equal(repr(Linq([])), 'Linq<>')
def test_init4(self): IGroup([ IPair(0, Linq([1, 2, 3])), IPair(1, Linq([2, 3, 4])), IPair(1, Linq([2, 3, 4])) ])
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))