def longest_string(a): return max(a.split(), key=len)
- def longest_string(a):
return max(a.split(),key=len)- return max(a.split(), key=len)
import unittest from solution import longest_string class TestLongestString(unittest.TestCase): def setUp(self) -> None: self.test_samples = (('codewars longest string code challenge', 'challenge'), ('Guido van Rossum created the Python programming language', 'programming'), ("Python was named after the TV comedy series 'Monty Python’s Flying Circus'", 'Python’s'), ('Python is an open-source object-oriented programming language.', 'object-oriented'), ('Python does not require a compiler', 'compiler'), ('Elvis Presley was born in Mississippi 1/8/1935', 'Mississippi'), ('Pneumonoultramicroscopicsilicovolcanoconiosis is a lung disease caused by inhalation of very fine silicate or quartz dust.', 'Pneumonoultramicroscopicsilicovolcanoconiosis') ) def test_longest_string(self): for sample, expected in self.test_samples: self.assertEqual(longest_string(sample), expected) if __name__ == '__main__': unittest.main()
- import unittest
- from solution import longest_string
- class TestLongestString(unittest.TestCase):
- def setUp(self) -> None:
- self.test_samples = (('codewars longest string code challenge', 'challenge'),
- ('Guido van Rossum created the Python programming language', 'programming'),
- ("Python was named after the TV comedy series 'Monty Python’s Flying Circus'", 'Python’s'),
- ('Python is an open-source object-oriented programming language.', 'object-oriented'),
- ('Python does not require a compiler', 'compiler'),
- ('Elvis Presley was born in Mississippi 1/8/1935', 'Mississippi'),
- ('Pneumonoultramicroscopicsilicovolcanoconiosis is a lung disease caused by inhalation of very fine silicate or quartz dust.',
- 'Pneumonoultramicroscopicsilicovolcanoconiosis')
- )
- def test_longest_string(self):
- for sample, expected in self.test_samples:
- self.assertEqual(longest_string(sample), expected)
- if __name__ == '__main__':
- unittest.main()