subtree(users/wpcarro): docking briefcase at '24f5a642'
git-subtree-dir: users/wpcarro git-subtree-mainline:464bbcb15cgit-subtree-split:24f5a642afChange-Id: I6105b3762b79126b3488359c95978cadb3efa789
This commit is contained in:
commit
019f8fd211
766 changed files with 175420 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
import unittest
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def has_palindrome_permutation(xs):
|
||||
vs = Counter(xs).values()
|
||||
return len([v for v in vs if v % 2 == 1]) in {0, 1}
|
||||
|
||||
|
||||
# Tests
|
||||
class Test(unittest.TestCase):
|
||||
def test_permutation_with_odd_number_of_chars(self):
|
||||
result = has_palindrome_permutation('aabcbcd')
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_permutation_with_even_number_of_chars(self):
|
||||
result = has_palindrome_permutation('aabccbdd')
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_no_permutation_with_odd_number_of_chars(self):
|
||||
result = has_palindrome_permutation('aabcd')
|
||||
self.assertFalse(result)
|
||||
|
||||
def test_no_permutation_with_even_number_of_chars(self):
|
||||
result = has_palindrome_permutation('aabbcd')
|
||||
self.assertFalse(result)
|
||||
|
||||
def test_empty_string(self):
|
||||
result = has_palindrome_permutation('')
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_one_character_string(self):
|
||||
result = has_palindrome_permutation('a')
|
||||
self.assertTrue(result)
|
||||
|
||||
|
||||
unittest.main(verbosity=2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue