Exemplo n.º 1
0
 def test_union_scores(self):
     s1 = FakeScorer(1, 2, 3)
     s2 = FakeScorer(2, 4, 8)
     s3 = FakeScorer(2, 3, 8)
     result = [(1, 10), (2, 30), (3, 20), (4, 10), (8, 20)]
     uqs = UnionScorer([s1, s2, s3])
     self.assertEqual(list(uqs), result)
Exemplo n.º 2
0
 def test_union(self):
     s1 = FakeScorer(1, 2, 3, 4, 5, 6, 7, 8)
     s2 = FakeScorer(2, 4, 8, 10, 20, 30)
     s3 = FakeScorer(10, 100, 200)
     result = [1, 2, 3, 4, 5, 6, 7, 8, 10, 20, 30, 100, 200]
     uqs = UnionScorer([s1, s2, s3])
     self.assertEqual(list(uqs.ids()), result)
Exemplo n.º 3
0
    def test_random_andnot(self):
        testcount = 100
        rangesize = 100

        rng = range(rangesize)

        for testnum in xrange(testcount):
            negs = sorted(sample(rng, randint(0, rangesize - 1)))
            negset = frozenset(negs)
            matched = [n for n in rng if n not in negset]
            pos = FakeScorer(*rng)
            neg = FakeScorer(*negs)
            ans = AndNotScorer(pos, neg)
            ids = list(ans.all_ids())
            self.assertEqual(ids, matched)
Exemplo n.º 4
0
 def test_inverse(self):
     s = FakeScorer(1, 5, 10, 11, 13)
     inv = InverseScorer(s, 15, lambda id: False)
     scores = []
     while inv.id is not None:
         scores.append(inv.id)
         inv.next()
     self.assertEqual(scores, [0, 2, 3, 4, 6, 7, 8, 9, 12, 14])
Exemplo n.º 5
0
    def test_empty_andnot(self):
        pos = EmptyScorer()
        neg = EmptyScorer()
        ans = AndNotScorer(pos, neg)
        ids = list(ans.all_ids())
        self.assertEqual(ids, [])

        pos = FakeScorer(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
        neg = EmptyScorer()
        ans = AndNotScorer(pos, neg)
        ids = list(ans.all_ids())
        self.assertEqual(ids, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Exemplo n.º 6
0
    def test_random_union(self):
        testcount = 1000
        rangelimits = (2, 10)
        clauselimits = (2, 10)

        vals = range(100)

        for testnum in xrange(testcount):
            matches = set()
            scorers = []
            for _ in xrange(randint(*clauselimits)):
                nums = sample(vals, randint(*rangelimits))
                matches = matches.union(nums)
                scorers.append(FakeScorer(*sorted(nums)))
            matches = sorted(matches)
            uqs = UnionScorer(scorers)
            self.assertEqual(list(uqs.ids()), matches)
Exemplo n.º 7
0
 def test_andnot(self):
     pos = FakeScorer(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     neg = FakeScorer(1, 2, 5, 7, 8, 10)
     ans = AndNotScorer(pos, neg)
     ids = list(ans.all_ids())
     self.assertEqual(ids, [3, 4, 6, 9])