1.1 --- a/test.py Sat Nov 20 23:56:16 2010 +0100
1.2 +++ b/test.py Sun Nov 21 20:44:43 2010 +0100
1.3 @@ -5,11 +5,12 @@
1.4 from iixr.terms import *
1.5 from iixr.positions import *
1.6 from iixr.index import *
1.7 +from array import array
1.8 import os, sys
1.9
1.10 # Remove old test files.
1.11
1.12 -for filename in ("test", "testF", "testFI", "testI", "testP", "testPI"):
1.13 +for filename in ("test", "testMS", "testNMS", "testF", "testFI", "testI", "testP", "testP2", "testPI"):
1.14 try:
1.15 os.remove(filename)
1.16 except OSError:
1.17 @@ -43,6 +44,44 @@
1.18 print number == n, number, n
1.19 r.close()
1.20
1.21 +tuples = [(0, 0), (1, 3), (2, 5), (3, 9)]
1.22 +
1.23 +f = open("testMS", "wb")
1.24 +w = FileWriter(f)
1.25 +b = array("B")
1.26 +last = w.get_initial_value(2)
1.27 +for t in tuples:
1.28 + last = w.write_sequence(b, t, last, 2)
1.29 +b.tofile(w.f)
1.30 +w.close()
1.31 +
1.32 +f = open("testMS", "rb")
1.33 +r = FileReader(f)
1.34 +last = r.get_initial_value(2)
1.35 +for t in tuples:
1.36 + last = t2 = r.read_sequence(last, 2)
1.37 + print t == t2, t, t2
1.38 +r.close()
1.39 +
1.40 +tuples2 = [(0, 0), (1, 3), (2, 1), (3, 2), (4, 0)]
1.41 +
1.42 +f = open("testNMS", "wb")
1.43 +w = FileWriter(f)
1.44 +b = array("B")
1.45 +last = w.get_initial_value(2)
1.46 +for t in tuples2:
1.47 + last = w.write_sequence(b, t, last, 2, monotonic=0)
1.48 +b.tofile(w.f)
1.49 +w.close()
1.50 +
1.51 +f = open("testNMS", "rb")
1.52 +r = FileReader(f)
1.53 +last = r.get_initial_value(2)
1.54 +for t in tuples2:
1.55 + last = t2 = r.read_sequence(last, 2, monotonic=0)
1.56 + print t == t2, t, t2
1.57 +r.close()
1.58 +
1.59 print "- Test positions."
1.60
1.61 all_doc_positions = [
1.62 @@ -77,6 +116,38 @@
1.63 r.reset()
1.64 r.close()
1.65
1.66 +all_doc_positions_seq = [
1.67 + [
1.68 + ((123, 0), [(1, 5), (3, 9), (5, 15), (15, 45), (25, 70)]),
1.69 + ((124, 1), [(0, 0), (100, 350)]),
1.70 + ((124, 2), [(11, 38), (99, 379), (199, 720)]),
1.71 + ((130, 0), [(77, 286), (78, 290), (80, 300), (82, 304), (89, 316)])
1.72 + ],
1.73 + [
1.74 + ((78, 1), [(9, 19)]),
1.75 + ((196, 0), [(10, 27), (11, 29)]),
1.76 + ((196, 1), [(17, 46), (21, 52), (30, 60)])
1.77 + ]
1.78 + ]
1.79 +
1.80 +f = open("testP2", "wb")
1.81 +w = PositionWriter(f)
1.82 +for doc_positions in all_doc_positions_seq:
1.83 + for docnum, positions in doc_positions:
1.84 + w.write_positions(docnum, positions)
1.85 + w.reset()
1.86 +w.close()
1.87 +
1.88 +f = open("testP2", "rb")
1.89 +r = PositionReader(f)
1.90 +for doc_positions in all_doc_positions_seq:
1.91 + for docnum, positions in doc_positions:
1.92 + d, p = r.read_positions()
1.93 + print tuple(docnum) == tuple(d), docnum, d
1.94 + print tuple(positions) == tuple(p), positions, p
1.95 + r.reset()
1.96 +r.close()
1.97 +
1.98 print "- Test position index files."
1.99
1.100 indexed_positions = [