Ejemplo n.º 1
0
    def test_uniq(self):
        tlist = [1, 2, 1, 3, 1, 4]
        self.assertEqual([1, 2, 3, 4], _.uniq(tlist),
                         'can find the unique values of an unsorted array')

        tlist = [1, 1, 1, 2, 2, 3]
        self.assertEqual([1, 2, 3], _.uniq(tlist, True),
                         'can find the unique values of a sorted array faster')

        tlist = [{
            "name": 'moe'
        }, {
            "name": 'curly'
        }, {
            "name": 'larry'
        }, {
            "name": 'curly'
        }]
        iterator = lambda value, *args: value.get('name')
        self.assertEqual(
            ["moe", "curly", "larry"], _.uniq(tlist, False, iterator),
            'can find the unique values of an array using a custom iterator')

        tlist = [1, 2, 2, 3, 4, 4]
        iterator = lambda value, *args: value + 1
        self.assertEqual([2, 3, 4, 5], _.uniq(tlist, True, iterator),
                         'iterator works with sorted array')
Ejemplo n.º 2
0
    def test_uniq(self):
        tlist = [1, 2, 1, 3, 1, 4]
        self.assertEqual([1, 2, 3, 4], _.uniq(tlist), 'can find the unique values of an unsorted array')

        tlist = [1, 1, 1, 2, 2, 3]
        self.assertEqual([1, 2, 3], _.uniq(tlist, True), 'can find the unique values of a sorted array faster')

        tlist = [{"name": 'moe'}, {"name": 'curly'}, {"name": 'larry'}, {"name": 'curly'}]
        iterator = lambda value, *args: value.get('name')
        self.assertEqual(["moe", "curly", "larry"], _.uniq(tlist, False, iterator), 'can find the unique values of an array using a custom iterator')

        tlist = [1, 2, 2, 3, 4, 4]
        iterator = lambda value, *args: value + 1
        self.assertEqual([2, 3, 4, 5], _.uniq(tlist, True, iterator), 'iterator works with sorted array')
Ejemplo n.º 3
0
    def test_uniqueId(self):
        ns = self.Namespace()
        ns.ids = []
        i = 0
        for i in range(0, 100):
            ns.ids.append(_.uniqueId())

        self.assertEqual(len(ns.ids), len(_.uniq(ns.ids)), "can generate a globally-unique stream of ids")
Ejemplo n.º 4
0
    def test_uniqueId(self):
        ns = self.Namespace()
        ns.ids = []
        i = 0
        for i in range(0, 100):
            ns.ids.append(_.uniqueId())

        self.assertEqual(len(ns.ids), len(_.uniq(ns.ids)),
                         "can generate a globally-unique stream of ids")