Exemple #1
0
    def test_count_manynonunique(self):
        """The count method should work with very many nonunique items"""
        for rep in xrange(2000):
            items = range(random.randint(1, 50))
            random.shuffle(items)
            itemcounts = [random.randint(0, 16) for _ in items]
            xs = [y for x in [[i] * itemcounts[i] for i in items] for y in x]

            ls = LazySorted(xs)
            for item in items:
                self.assertEqual(ls.count(item), itemcounts[item])

        for n in TestLazySorted.test_lengths:
            ls = LazySorted([0] * n)
            self.assertEqual(ls.count(0), n)
Exemple #2
0
    def test_count_manynonunique(self):
        """The count method should work with very many nonunique items"""
        for rep in xrange(2000):
            items = range(random.randint(1, 50))
            random.shuffle(items)
            itemcounts = [random.randint(0, 16) for _ in items]
            xs = [y for x in [[i] * itemcounts[i] for i in items] for y in x]

            ls = LazySorted(xs)
            for item in items:
                self.assertEqual(ls.count(item), itemcounts[item])

        for n in TestLazySorted.test_lengths:
            ls = LazySorted([0] * n)
            self.assertEqual(ls.count(0), n)
Exemple #3
0
    def test_count_nonunique(self):
        """The count method should work in the presence of nonunique items"""
        for a in xrange(1, 32):
            for b in xrange(1, 32):
                xs = a * ["a"] + b * ["b"]
                for rep in xrange(3):
                    random.shuffle(xs)
                    ls = LazySorted(xs)

                    self.assertEqual(ls.count("b"), b)
                    self.assertEqual(ls.count("a"), a)

                for rep in xrange(3):
                    random.shuffle(xs)
                    ls = LazySorted(xs)

                    self.assertEqual(ls.count("a"), a)
                    self.assertEqual(ls.count("b"), b)
Exemple #4
0
    def test_count_nonunique(self):
        """The count method should work in the presence of nonunique items"""
        for a in xrange(1, 32):
            for b in xrange(1, 32):
                xs = a * ["a"] + b * ["b"]
                for rep in xrange(3):
                    random.shuffle(xs)
                    ls = LazySorted(xs)

                    self.assertEqual(ls.count("b"), b)
                    self.assertEqual(ls.count("a"), a)

                for rep in xrange(3):
                    random.shuffle(xs)
                    ls = LazySorted(xs)

                    self.assertEqual(ls.count("a"), a)
                    self.assertEqual(ls.count("b"), b)
Exemple #5
0
 def test_count_simple(self):
     """The count method should work on simple queries"""
     for n in TestLazySorted.test_lengths:
         xs = range(n)
         ys = range(0, n, 5) + [-4, -3, -2, -1, 0, n, n + 1, n + 2, 3.3]
         for rep in xrange(5):
             random.shuffle(xs)
             random.shuffle(ys)
             ls = LazySorted(xs)
             for y in ys:
                 self.assertEqual(ls.count(y), 1 if (isinstance(y, int) and
                                  0 <= y < n) else 0)
Exemple #6
0
 def test_count_simple(self):
     """The count method should work on simple queries"""
     for n in TestLazySorted.test_lengths:
         xs = range(n)
         ys = range(0, n, 5) + [-4, -3, -2, -1, 0, n, n + 1, n + 2, 3.3]
         for rep in xrange(5):
             random.shuffle(xs)
             random.shuffle(ys)
             ls = LazySorted(xs)
             for y in ys:
                 self.assertEqual(
                     ls.count(y), 1 if
                     (isinstance(y, int) and 0 <= y < n) else 0)