def test_longest_common_prefix(self):
     solution = Solution()
     self.assertEqual(
         solution.longestCommonPrefix(["flower", "flow", "flight"]), 'fl')
     self.assertEqual(
         solution.longestCommonPrefix(["dog", "racecar", "car"]), '')
     self.assertEqual(solution.longestCommonPrefix(["aa", "a"]), "a")
예제 #2
0
 def test_longest_common_prefix(self):
     solution = Solution()
     # actual = solution.longest_common_prefix(["a", "a", "b"])
     # self.assertEqual("", actual)
     # actual = solution.longest_common_prefix(["a", "a"])
     # self.assertEqual("a", actual)
     actual = solution.longest_common_prefix(["abca", "abc"])
     self.assertEqual("abc", actual)
예제 #3
0
class TestLongestCommonPrefix(unittest.TestCase):

    def setUp(self):
        self.lcp = LongestCommonPrefix()

    def test_longest_common_prefix(self):
        self.assertEqual(
            "fl", self.lcp.longestCommonPrefix(["flower", "flow", "flight"]))
        self.assertEqual(
            "", self.lcp.longestCommonPrefix(["dog", "racecar", "car"]))
예제 #4
0
class Tester(unittest.TestCase):
    def setUp(self):
        self.s = Solution()

    @data([["abc", "abc", "ab"], "ab"], [["abc", "abc", "ab", "a"], "a"],
          [["bc", "abc", "ab", "a"], ""], [["flower", "flow", "flight"], "fl"])
    @unpack
    def test(self, strs, expected):
        ret = self.s.longestCommonPrefix(strs)
        self.assertEqual(ret, expected)
예제 #5
0
class LongestCommonPrefixTests(unittest.TestCase):
    """Test Suite to execute unit tests for all common prefix cases"""
    def setUp(self) -> None:
        self.obj = Solution()

    def test_common_prefix_works_for_single_letter_prefix(self):
        words = ['a', 'ab', 'abc']
        expected = 'a'
        calculated = self.obj.longestCommonPrefix(words)
        self.assertEqual(calculated, expected)

    def test_common_prefix_works_for_double_letter_prefix(self):
        words = ['xy', 'xyz', 'xyzz']
        expected = 'xy'
        calculated = self.obj.longestCommonPrefix(words)
        self.assertEqual(calculated, expected)

    def test_common_prefix_returns_blank_string_for_valid_cases(self):
        words = ['Mr', 'Sr', 'Res', 'Hon.', 'Sra']
        expected = ''
        calculated = self.obj.longestCommonPrefix(words)
        self.assertEqual(calculated, expected)

    def test_common_prefix_returns_blank_string_for_one_uncommon_word(self):
        words = ['Mr', 'Mrs', 'Mra', 'mrA', 'Sra']
        expected = ''
        calculated = self.obj.longestCommonPrefix(words)
        self.assertEqual(calculated, expected)

    def test_common_prefix_works_for_long_prefixes(self):
        words = [
            'Sr. # 1. Doctor', 'Sr. # 1. Doctorate',
            'Sr. # 1. Doctors in Medical'
        ]
        expected = 'Sr. # 1. Doctor'
        calculated = self.obj.longestCommonPrefix(words)
        self.assertEqual(calculated, expected)

    def test_common_prefix_works_for_intermediate_spaces_in_words(self):
        words = [
            'Inr Usd ', 'Inr Usd Aus', 'Inr Usd Aus Yen', 'Inr Usd Aus Yen Gbp'
        ]
        expected = 'Inr Usd'
        calculated = self.obj.longestCommonPrefix(words)
        self.assertEqual(calculated, expected)
예제 #6
0
    def test_one(self):

        solution = Solution()
        
        self.assertEqual(solution.longestCommonPrefix(["flower","flow","flight"]), 'fl')
예제 #7
0
    def test_two(self):

        solution = Solution()
        
        self.assertEqual(solution.longestCommonPrefix(["dog","racecar","car"]), '')
예제 #8
0
 def test_Calculate_Solution(self):
     sol = Solution()
     self.assertEqual('fl',
                      sol.longestCommonPrefix(['flower', 'flow', 'flight']))
     self.assertEqual('', sol.longestCommonPrefix(['dog', 'racecar',
                                                   'car']))
예제 #9
0
 def setUp(self):
     self.solution = Solution()
     self.test = self.solution.longest_common_prefix
예제 #10
0
 def setUp(self):
     self.s = Solution()
예제 #11
0
 def setUp(self) -> None:
     self.obj = Solution()
예제 #12
0
 def setUp(self):
     self.lcp = LongestCommonPrefix()
예제 #13
0
 def test_longest_common_prefix(self):
     inputs = (["flower", "flow", "flight"], ["dog", "racecar",
                                              "car"], ["", "b"])
     outs = ('fl', '', "")
     for inp, out in zip(inputs, outs):
         self.assertEqual(out, Solution().longestCommonPrefix(inp))