Serie | treffen:problemsolving |
Von | nopx |
Datum | 06.Juli 2021 |
Download | Aufgabenbeschreibung [pdf,v2] |
Schwierigkeit | ![]() |
Some unittests
#!/bin/python import unittest from main import eval class Test(unittest.TestCase): def test(self): self.assertEqual(1, eval("aba")) self.assertEqual(1, eval("abcbabc")) self.assertEqual(1, eval("abcabc")) self.assertEqual(1, eval("aa")) self.assertEqual(0, eval("a")) self.assertEqual(0, eval("")) self.assertEqual(1, eval("a" * 498 + "b" + "g" + "b" + "a" * 498)) self.assertEqual(1, eval("a" * 497 + "b" + "ghg" + "b" + "a" * 497)) self.assertEqual(1, eval("aaahalloa")) if __name__ == "__main__": unittest.main()
def eval(s): for i in range(1,1+len(s)//2): if s[:i] == s[-i:]: return 1 return 0