コード例 #1
0
    def test_get_window_simple_two_line(self):
        result = self.x.find_supplemented_window_lim('Вторая', 1, 0, 1,
                                                     [(0, 1)])
        res = result['test_window_three.txt'][0]

        result1 = self.x.find_supplemented_window_lim_v2(
            'Вторая', 1, 0, 1, [(0, 1)])
        res1 = result1['test_window_three.txt'][0]

        win = TokenWindow(self.strr4, [Position(0, 6, 1)], 0, 25)
        ideal = {'test_window_three.txt': [win]}

        self.assertEqual(res.allString, win.allString)
        self.assertEqual(res, win)
        self.assertEqual(result, ideal)

        self.assertEqual(res1.allString, win.allString)
        self.assertEqual(res1, win)
        self.assertEqual(result1, ideal)
コード例 #2
0
    def test_get_window_two_result3(self):
        result = self.x.find_supplemented_window_lim('тестов', 1, 0, 1,
                                                     [(1, 2)])
        res1 = result['test_window_three.txt'][0]

        result1 = self.x.find_supplemented_window_lim_v2(
            'тестов', 1, 0, 1, [(1, 2)])
        res11 = result1['test_window_three.txt'][0]

        win1 = TokenWindow(self.strr4.replace('\n', ''), [Position(18, 24, 1)],
                           0, 25)
        ideal = {'test_window_three.txt': [win1]}

        self.assertEqual(res1.allString, win1.allString)
        self.assertEqual(res1, win1)
        self.assertEqual(result, ideal)

        self.assertEqual(res11.allString, win1.allString)
        self.assertEqual(res11, win1)
        self.assertEqual(result1, ideal)
コード例 #3
0
 def test_database_created(self):
     file = open('test.txt', 'w')
     file.write('Baikal')
     file.close()
     self.x.prescribe_index('test.txt')
     '''
     The method listdir() returns a list containing the names of the entries in the directory given by path.
     '''
     files = os.listdir(path=".")
     flag = False
     for f in files:
         if f.startswith('database.'):
             flag = True
         elif f.startswith('database'):
             if f == 'database':
                 flag = True
     self.assertEqual(flag, True)
     db_dict = dict(self.x.db)
     standart_result = {'Baikal': {'test.txt': [Position(0, 6, 0)]}}
     self.assertEqual(db_dict, standart_result)
     os.remove('test.txt')
コード例 #4
0
import unittest
from searchengine import SearchEngine, TokenWindow
from indexer import Position
import os

idealdict = {
    'sun': {
        'test_window_one.txt': [Position(0, 3, 0)]
    },
    'window': {
        'test_window_one.txt': [Position(4, 10, 0)]
    },
    'tree': {
        'test_window_one.txt': [Position(11, 15, 0)]
    },
    'apple': {
        'test_window_one.txt': [Position(16, 21, 0)]
    },
    'juse': {
        'test_window_one.txt': [Position(23, 27, 0)]
    },
    'border': {
        'test_window_one.txt': [Position(28, 34, 0)]
    },
    'films': {
        'test_window_one.txt': [Position(35, 40, 0)]
    },
    '23': {
        'test_window_one.txt': [Position(41, 43, 0)]
    },
    '45': {
コード例 #5
0
 def test_search_two_tokens(self):
     result = self.x.multiple_search('The sun')
     self.assertIsInstance(result, dict)
     self.assertEqual(result,
                      {'file2.txt': [Position(1, 4, 0),
                                     Position(5, 8, 0)]})
コード例 #6
0
import unittest
from searchengine import SearchEngine
from indexer import Position
import shelve
import os

file1 = " The Earth is round"
file2 = " The sun is round"
idealdict = {
    'sun': {
        'file2.txt': [Position(5, 8, 0)]
    },
    'The': {
        'file1.txt': [Position(1, 4, 0)],
        'file2.txt': [Position(1, 4, 0)]
    },
    'Earth': {
        'file1.txt': [Position(5, 10, 0)]
    },
    'round': {
        'file1.txt': [Position(14, 19, 0)],
        'file2.txt': [Position(12, 17, 0)]
    },
    'is': {
        'file1.txt': [Position(11, 13, 0)],
        'file2.txt': [(9, 11, 0)]
    }
}


class TestMySearchEngine(unittest.TestCase):
コード例 #7
0
 def test_get_window_two_result3(self):
     result = self.x.multiple_search_lim('тестов', 0, 1)
     res1 = result['test_window_three.txt'][0]
     t = [Position(18, 24, 0), Position(18, 24, 1)]
     ideal = {'test_window_three.txt': t}
     self.assertEqual(result, ideal)
コード例 #8
0
 def test_get_window_simple_two_line(self):
     result = self.x.multiple_search_lim('Вторая', 0, 1)
     res = result['test_window_three.txt'][0]
     t = [Position(0, 6, 1)]
     ideal = {'test_window_three.txt': t}
     self.assertEqual(result, ideal)
コード例 #9
0
 def test_get_window_simple2(self):
     result = self.x.multiple_search_lim('нашу', 0, 1)
     res = result['test_window_two.txt'][0]
     t = [Position(13, 17, 0)]
     ideal = {'test_window_two.txt': t}
     self.assertEqual(result, ideal)
コード例 #10
0
 def test_get_window_end(self):
     result = self.x.multiple_search_lim('good', 0, 1)
     res = result['test_window_one.txt'][0]
     t = [Position(46, 50, 0)]
     ideal = {'test_window_one.txt': t}
     self.assertEqual(result, ideal)
コード例 #11
0
 def test_get_window_simple(self):
     result = self.x.multiple_search_lim('tree', 0, 1)
     res = result['test_window_one.txt'][0]
     t = [Position(11, 15, 0)]
     ideal = {'test_window_one.txt': t}
     self.assertEqual(result, ideal)
コード例 #12
0
 def test_get_window_begin(self):
     result = self.x.multiple_search_lim('sun', 0, 1)
     res = result['test_window_one.txt'][0]
     t = [Position(0, 3, 0)]
     ideal = {'test_window_one.txt': t}
     self.assertEqual(result, ideal)
コード例 #13
0
 def test_get_window_simple_two_line(self):
     result = self.x.multiple_search_lim_gen('Вторая', 0, 1)
     t = self.x.merge_and_sort_lists([[Position(0, 6, 1)]])
     ideal = {'test_window_three.txt': t}
     self.assertEqual(list(result['test_window_three.txt']),
                      list(ideal['test_window_three.txt']))
コード例 #14
0
 def test_get_window_simple2(self):
     result = self.x.multiple_search_lim_gen('нашу', 0, 1)
     t = self.x.merge_and_sort_lists([[Position(13, 17, 0)]])
     ideal = {'test_window_two.txt': t}
     self.assertEqual(list(result['test_window_two.txt']),
                      list(ideal['test_window_two.txt']))
コード例 #15
0
 def test_get_window_end(self):
     result = self.x.multiple_search_lim_gen('good', 0, 1)
     t = self.x.merge_and_sort_lists([[Position(46, 50, 0)]])
     ideal = {'test_window_one.txt': t}
     self.assertEqual(list(result['test_window_one.txt']),
                      list(ideal['test_window_one.txt']))
コード例 #16
0
 def test_get_window_simple(self):
     result = self.x.multiple_search_lim_gen('tree', 0, 1)
     t = self.x.merge_and_sort_lists([[Position(11, 15, 0)]])
     ideal = {'test_window_one.txt': t}
     self.assertEqual(list(result['test_window_one.txt']),
                      list(ideal['test_window_one.txt']))