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')
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')
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")