Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Fairly massive rearrangement to allow the Okapi indexer to reuse
Browse files Browse the repository at this point in the history
testStopWords().  That isn't the real point.  The real point is to
fiddle the scaffolding enough to make it possible to run a white box
test of the Okapi indexer too.  That isn't here yet.
  • Loading branch information
Tim Peters committed May 16, 2002
1 parent b643ff9 commit 227082f
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions tests/testZCTextIndex.py
Expand Up @@ -30,15 +30,18 @@ def eq(scaled1, scaled2, epsilon=scaled_int(0.01)):
if abs(scaled1 - scaled2) > epsilon:
raise AssertionError, "%s != %s" % (scaled1, scaled2)

class IndexTests(testIndex.CosineIndexTest):
# Subclasses should derive from one of testIndex.{CosineIndexTest,
# OkapiIndexTest} too.

class ZCIndexTestsBase:

def setUp(self):
extra = Extra()
extra.doc_attr = 'text'
extra.lexicon_id = 'lexicon'
caller = LexiconHolder(Lexicon(Splitter(), CaseNormalizer(),
StopWordRemover()))
self.zc_index = ZCTextIndex('name', extra, caller, CosineIndex)
self.zc_index = ZCTextIndex('name', extra, caller, self.IndexFactory)
self.index = self.zc_index.index
self.lexicon = self.zc_index.lexicon

Expand All @@ -54,10 +57,15 @@ def testStopWords(self):
self.assertEqual(wids, [])
self.assertEqual(len(self.index._get_undoinfo(1)), 1)


class CosineIndexTests(ZCIndexTestsBase, testIndex.CosineIndexTest):

# A fairly involved test of the ranking calculations based on
# an example set of documents in queries in Managing
# Gigabytes, pp. 180-188. This test peeks into many internals of the
# cosine index.

def testRanking(self):
# A fairly involved test of the ranking calculations based on
# an example set of documents in queries in Managing
# Gigabytes, pp. 180-188.
self.words = ["cold", "days", "eat", "hot", "lot", "nine", "old",
"pease", "porridge", "pot"]
self._ranking_index()
Expand Down Expand Up @@ -127,6 +135,10 @@ def _ranking_queries(self):
self.assert_(0 <= score <= SCALE_FACTOR)
eq(d[doc], score)

class OkapiIndexTests(ZCIndexTestsBase, testIndex.OkapiIndexTest):
pass

############################################################################
# Subclasses of QueryTestsBase must set a class variable IndexFactory to
# the kind of index to be constructed.

Expand Down Expand Up @@ -173,9 +185,12 @@ class CosineQueryTests(QueryTestsBase):
class OkapiQueryTests(QueryTestsBase):
IndexFactory = OkapiIndex

############################################################################

def test_suite():
s = unittest.TestSuite()
for klass in IndexTests, CosineQueryTests, OkapiQueryTests:
for klass in (CosineIndexTests, OkapiIndexTests,
CosineQueryTests, OkapiQueryTests):
s.addTest(unittest.makeSuite(klass))
return s

Expand Down

0 comments on commit 227082f

Please sign in to comment.