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")
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)
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"]))
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)
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)
def test_one(self): solution = Solution() self.assertEqual(solution.longestCommonPrefix(["flower","flow","flight"]), 'fl')
def test_two(self): solution = Solution() self.assertEqual(solution.longestCommonPrefix(["dog","racecar","car"]), '')
def test_Calculate_Solution(self): sol = Solution() self.assertEqual('fl', sol.longestCommonPrefix(['flower', 'flow', 'flight'])) self.assertEqual('', sol.longestCommonPrefix(['dog', 'racecar', 'car']))
def setUp(self): self.solution = Solution() self.test = self.solution.longest_common_prefix
def setUp(self): self.s = Solution()
def setUp(self) -> None: self.obj = Solution()
def setUp(self): self.lcp = LongestCommonPrefix()
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))