示例#1
0
    def test_first(self):
        data = [1, 2, 3]
        ret = Q(data).first()

        self.assertEqual(1, ret)
示例#2
0
 def test_single_on_empty(self):
     data = []
     self.assertRaises(ValueError, lambda: Q(data).single())
示例#3
0
    def test_last(self):
        data = [1, 2, 3]
        ret = Q(data).last()

        self.assertEqual(3, ret)
示例#4
0
 def test_last_on_empty(self):
     data = []
     self.assertRaises(ValueError, lambda: Q(data).last())
示例#5
0
    def test_without_value_selector(self):
        data = ("one", "two", "four")
        ret = Q(data).to_dict(lambda x: x[0])

        self.assertIsInstance(ret, dict)
        self.assertEqual({"o": "one", "t": "two", "f": "four"}, ret)
示例#6
0
 def test_take_n(self):
     data = [1, 2, 3, 4, 5, 1, 2, 4, 8, 16, 32]
     ret = Q(data).take(5).to_list()
     self.assertSequenceEqual((1, 2, 3, 4, 5), ret)
示例#7
0
    def test_shorter_sequence(self):
        data = [1, 2, 3]

        self.assertFalse(Q(data).sequence_equal((1, 2)))
示例#8
0
    def test_default_on_empty(self):
        data = ()
        ret = Q(data).default_if_empty("default").to_tuple()

        self.assertEqual(("default", ), ret)
示例#9
0
    def test_without_initializer(self):
        data = (1, 2, 3)
        ret = Q(data).reduce(lambda a, b: a + b)

        self.assertEqual(6, ret)
示例#10
0
    def test_with_initializer(self):
        data = (1, 2, 3)
        ret = Q(data).reduce([], lambda a, b: a + [b])

        self.assertSequenceEqual(data, ret)
示例#11
0
    def test_list(self):
        data = [1, 2, 3]
        ret = Q(data).to_tuple()

        self.assertIsInstance(ret, tuple)
        self.assertSequenceEqual(data, ret)
示例#12
0
    def test_single(self):
        data = [1]
        ret = Q(data).single()

        self.assertEqual(1, ret)
示例#13
0
 def test_single_or_default_on_multi(self):
     data = [1, 2, 3]
     self.assertRaises(ValueError, lambda: Q(data).single_or_default(0))
示例#14
0
 def test_something(self):
     data = (1, 2, 3)
     ret = Q(data)
     self.assertTrue(all(a == b for a, b in zip_longest(data, ret)))
示例#15
0
    def test_longer_sequence(self):
        data = [1, 2, 3]

        self.assertFalse(Q(data).sequence_equal((1, 2, 3, 4)))
示例#16
0
    def test_default_on_non_empty(self):
        data = ("foo", "bar")
        ret = Q(data).default_if_empty("default").to_tuple()

        self.assertEqual(("foo", "bar"), ret)
示例#17
0
    def test_different_sequence(self):
        data = [1, 2, 3]

        self.assertFalse(Q(data).sequence_equal((4, 5, 6)))
示例#18
0
    def test_with_value_selector(self):
        data = ("one", "two", "four")
        ret = Q(data).to_dict(lambda x: x[0], lambda x: ord(x[1]))

        self.assertIsInstance(ret, dict)
        self.assertEqual({"o": 110, "t": 119, "f": 111}, ret)
示例#19
0
    def test_same_sequence(self):
        data = [1, 2, 3]

        self.assertTrue(Q(data).sequence_equal((1, 2, 3)))
示例#20
0
 def test_take_while(self):
     data = [1, 2, 3, 4, 5, 1, 2, 4, 8, 16, 32]
     ret = Q(data).take_while(lambda x: x < 5).to_list()
     self.assertSequenceEqual((1, 2, 3, 4), ret)
示例#21
0
    def test_distinct_with_key_selector(self):
        data = (1, 1, 2, 5, 1)
        ret = Q(data).distinct(lambda x: x % 2).to_set()

        self.assertSetEqual({1, 2}, ret)
示例#22
0
    def test_first_or_default(self):
        data = [1, 2, 3]
        ret = Q(data).first_or_default(0)

        self.assertEqual(1, ret)
示例#23
0
    def test_ordered_distinct(self):
        data = (1, 1, 2, 5, 1)
        ret = Q(data).distinct_ordered().to_list()

        self.assertSequenceEqual([1, 2, 5, 1], ret)
示例#24
0
    def test_last_or_default(self):
        data = [1, 2, 3]
        ret = Q(data).last_or_default(0)

        self.assertEqual(3, ret)
示例#25
0
    def test_ordered_distinct_with_key_selector(self):
        data = (1, 1, 2, 5, 1)
        ret = Q(data).distinct_ordered(lambda x: x % 2).to_list()

        self.assertSequenceEqual([1, 2, 5], ret)
示例#26
0
    def test_last_or_default_on_empty(self):
        data = []
        ret = Q(data).last_or_default(0)

        self.assertEqual(0, ret)
示例#27
0
    def test_distinct(self):
        data = (1, 1, 2, 5, 1)
        ret = Q(data).distinct().to_set()

        self.assertSetEqual({1, 2, 5}, ret)
示例#28
0
    def test_join(self):
        data = ["hello", "world"]
        ret = Q(data).join(" and ")

        self.assertEqual("hello and world", ret)
示例#29
0
    def test_single_or_default(self):
        data = [1]
        ret = Q(data).single_or_default(0)

        self.assertEqual(1, ret)