def test_postings_file_write_entry_overwrite():
    filename = 'test'
    with PostingsFile(filename, 'w+') as pfile:
        assert_eq(0, pfile.pointer)
        write_location = 0

        entry = PostingsFileEntry(1)
        entry.own_pointer = write_location

        pfile.write_entry(entry)

        assert_eq(
            PostingsFileEntry(1).to_string(),
            pfile.read_entry(write_location))

        entry.next_pointer = 2
        pfile.write_entry(entry)

        assert_eq(
            PostingsFileEntry(1, 2).to_string(),
            pfile.read_entry(write_location))

        entry.skip_pointer = 3
        pfile.write_entry(entry)

        assert_eq(
            PostingsFileEntry(1, 2, 3).to_string(),
            pfile.read_entry(write_location))

    os.remove(filename)
def test_postings_file_get_entry_reset_false():
    filename = 'test'
    with PostingsFile(filename, 'w+') as pfile:
        head = pfile.pointer
        prev_ptr = head

        last = 12
        for i in xrange(1, last):
            current_entry = PostingsFileEntry(i)
            current_entry.own_pointer = pfile.pointer
            pfile.write_entry(current_entry)

            if i != last - 1:
                current_entry.next_pointer = pfile.pointer
                pfile.write_entry(current_entry)

        entries = []
        entry = pfile.get_entry(head, reset=False)
        while entry:
            entries.append(entry)
            entry = entry.next()
        entries = [entry.doc_id for entry in entries]
        assert_eq([1,2,3,4,5,6,7,8,9,10,11], entries)

    os.remove(filename)
Example #3
0
def test_postings_file_write_entry_overwrite():
    filename = 'test'
    with PostingsFile(filename, 'w+') as pfile:
        assert_eq(0, pfile.pointer)
        write_location = 0

        entry = PostingsFileEntry(1)
        entry.own_pointer = write_location

        pfile.write_entry(entry)

        assert_eq(
            PostingsFileEntry(1).to_string(), pfile.read_entry(write_location))

        entry.next_pointer = 2
        pfile.write_entry(entry)

        assert_eq(
            PostingsFileEntry(1, 2).to_string(),
            pfile.read_entry(write_location))

        entry.skip_pointer = 3
        pfile.write_entry(entry)

        assert_eq(
            PostingsFileEntry(1, 2, 3).to_string(),
            pfile.read_entry(write_location))

    os.remove(filename)
Example #4
0
def test_postings_file_get_entry_reset_false():
    filename = 'test'
    with PostingsFile(filename, 'w+') as pfile:
        head = pfile.pointer
        prev_ptr = head

        last = 12
        for i in xrange(1, last):
            current_entry = PostingsFileEntry(i)
            current_entry.own_pointer = pfile.pointer
            pfile.write_entry(current_entry)

            if i != last - 1:
                current_entry.next_pointer = pfile.pointer
                pfile.write_entry(current_entry)

        entries = []
        entry = pfile.get_entry(head, reset=False)
        while entry:
            entries.append(entry)
            entry = entry.next()
        entries = [entry.doc_id for entry in entries]
        assert_eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], entries)

    os.remove(filename)
def test_postings_file_get_entry_from_pointer():
    filename = 'test'
    with PostingsFile(filename, 'w+') as pfile:
        head = pfile.pointer
        prev_ptr = head

        last = 12
        for i in xrange(1, last):
            current_entry = PostingsFileEntry(i)
            current_entry.own_pointer = pfile.pointer
            pfile.write_entry(current_entry)

            if i != last - 1:
                current_entry.next_pointer = pfile.pointer
                pfile.write_entry(current_entry)

        entries = pfile.get_entry_list_from_pointer(head)
        entries = [entry.doc_id for entry in entries]
        assert_eq([1,2,3,4,5,6,7,8,9,10,11], entries)

    os.remove(filename)
Example #6
0
def test_postings_file_get_entry_from_pointer():
    filename = 'test'
    with PostingsFile(filename, 'w+') as pfile:
        head = pfile.pointer
        prev_ptr = head

        last = 12
        for i in xrange(1, last):
            current_entry = PostingsFileEntry(i)
            current_entry.own_pointer = pfile.pointer
            pfile.write_entry(current_entry)

            if i != last - 1:
                current_entry.next_pointer = pfile.pointer
                pfile.write_entry(current_entry)

        entries = pfile.get_entry_list_from_pointer(head)
        entries = [entry.doc_id for entry in entries]
        assert_eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], entries)

    os.remove(filename)