# Path: pyalgs/algorithms/strings/longest_repeated_substring.py
# class LongestRepeatedSubstringSearch(object):
#     @staticmethod
#     def lrs(text, pattern):
#         n = len(text)
#         a = [''] * n
#         for i in range(0, n):
#             a[i] = text[i:]
# 
#         sorted(a)
# 
#         max_len = 0
#         j = -1
#         for i in range(0, n):
#             l = LongestRepeatedSubstringSearch.lcp(a[i], pattern)
#             if l > max_len:
#                 j = i
#                 max_len = l
# 
#         return (j, max_len)
# 
#     @staticmethod
#     def lcp(text, pattern):
#         i = 0
#         for i in range(min(len(text), len(pattern))):
#             if text[i] != pattern[i]:
#                 return i
#         return i


import unittest
from pyalgs.algorithms.strings.longest_repeated_substring import LongestRepeatedSubstringSearch



class LongestRepeatedSubstringSearchUnitTest(unittest.TestCase):

    def test_lrs(self):
        start, len = LongestRepeatedSubstringSearch.lrs('Hello World', 'World Record')
        print('Hello World'[start:(start+len+1)])
        self.assertEqual('World', 'Hello World'[start:(start+len+1)])


if __name__ == '__main__':

# Path: pyalgs/algorithms/strings/longest_repeated_substring.py
# class LongestRepeatedSubstringSearch(object):
#     @staticmethod
#     def lrs(text, pattern):
#         n = len(text)
#         a = [''] * n
#         for i in range(0, n):
#             a[i] = text[i:]
# 
#         sorted(a)
# 
#         max_len = 0
#         j = -1
#         for i in range(0, n):
#             l = LongestRepeatedSubstringSearch.lcp(a[i], pattern)
#             if l > max_len:
#                 j = i
#                 max_len = l
# 
#         return (j, max_len)
# 
#     @staticmethod
#     def lcp(text, pattern):
#         i = 0
#         for i in range(min(len(text), len(pattern))):
#             if text[i] != pattern[i]:
#                 return i
#         return i


# Path: tests/algorithms/strings/longest_repeated_substring_unit_test.py
import unittest
from pyalgs.algorithms.strings.longest_repeated_substring import LongestRepeatedSubstringSearch




class LongestRepeatedSubstringSearchUnitTest(unittest.TestCase):

    def test_lrs(self):
        start, len = LongestRepeatedSubstringSearch.lrs('Hello World', 'World Record')
        print('Hello World'[start:(start+len+1)])
        self.assertEqual('World', 'Hello World'[start:(start+len+1)])


if __name__ == '__main__':

    unittest.main()