mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Move unique chars to a class
This commit is contained in:
parent
14a2751862
commit
8a7c14239c
|
@ -13,10 +13,13 @@ class TestUniqueChars(object):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
test = TestUniqueChars()
|
test = TestUniqueChars()
|
||||||
test.test_unique_chars(unique_chars)
|
unique_chars = UniqueChars()
|
||||||
|
test.test_unique_chars(unique_chars.has_unique_chars)
|
||||||
try:
|
try:
|
||||||
test.test_unique_chars(unique_chars_hash)
|
unique_chars_set = UniqueCharsSet()
|
||||||
test.test_unique_chars(unique_chars_inplace)
|
test.test_unique_chars(unique_chars_set.has_unique_chars)
|
||||||
|
unique_chars_in_place = UniqueCharsInPlace()
|
||||||
|
test.test_unique_chars(unique_chars_in_place.has_unique_chars)
|
||||||
except NameError:
|
except NameError:
|
||||||
# Alternate solutions are only defined
|
# Alternate solutions are only defined
|
||||||
# in the solutions file
|
# in the solutions file
|
||||||
|
|
|
@ -81,7 +81,9 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def unique_chars(string):\n",
|
"class UniqueChars(object):\n",
|
||||||
|
"\n",
|
||||||
|
" def has_unique_chars(self, string):\n",
|
||||||
" # TODO: Implement me\n",
|
" # TODO: Implement me\n",
|
||||||
" pass"
|
" pass"
|
||||||
]
|
]
|
||||||
|
@ -124,10 +126,13 @@
|
||||||
"\n",
|
"\n",
|
||||||
"def main():\n",
|
"def main():\n",
|
||||||
" test = TestUniqueChars()\n",
|
" test = TestUniqueChars()\n",
|
||||||
" test.test_unique_chars(unique_chars)\n",
|
" unique_chars = UniqueChars()\n",
|
||||||
|
" test.test_unique_chars(unique_chars.has_unique_chars)\n",
|
||||||
" try:\n",
|
" try:\n",
|
||||||
" test.test_unique_chars(unique_chars_hash)\n",
|
" unique_chars_set = UniqueCharsSet()\n",
|
||||||
" test.test_unique_chars(unique_chars_inplace)\n",
|
" test.test_unique_chars(unique_chars_set.has_unique_chars)\n",
|
||||||
|
" unique_chars_in_place = UniqueCharsInPlace()\n",
|
||||||
|
" test.test_unique_chars(unique_chars_in_place.has_unique_chars)\n",
|
||||||
" except NameError:\n",
|
" except NameError:\n",
|
||||||
" # Alternate solutions are only defined\n",
|
" # Alternate solutions are only defined\n",
|
||||||
" # in the solutions file\n",
|
" # in the solutions file\n",
|
||||||
|
|
|
@ -93,7 +93,9 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def unique_chars(string):\n",
|
"class UniqueCharsSet(object):\n",
|
||||||
|
"\n",
|
||||||
|
" def has_unique_chars(self, string):\n",
|
||||||
" if string is None:\n",
|
" if string is None:\n",
|
||||||
" return False\n",
|
" return False\n",
|
||||||
" return len(set(string)) == len(string)"
|
" return len(set(string)) == len(string)"
|
||||||
|
@ -138,7 +140,9 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def unique_chars_hash(string):\n",
|
"class UniqueChars(object):\n",
|
||||||
|
"\n",
|
||||||
|
" def has_unique_chars(self, string):\n",
|
||||||
" if string is None:\n",
|
" if string is None:\n",
|
||||||
" return False\n",
|
" return False\n",
|
||||||
" chars_set = set()\n",
|
" chars_set = set()\n",
|
||||||
|
@ -184,7 +188,9 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def unique_chars_inplace(string):\n",
|
"class UniqueCharsInPlace(object):\n",
|
||||||
|
"\n",
|
||||||
|
" def has_unique_chars(self, string):\n",
|
||||||
" if string is None:\n",
|
" if string is None:\n",
|
||||||
" return False\n",
|
" return False\n",
|
||||||
" for char in string:\n",
|
" for char in string:\n",
|
||||||
|
@ -232,10 +238,13 @@
|
||||||
"\n",
|
"\n",
|
||||||
"def main():\n",
|
"def main():\n",
|
||||||
" test = TestUniqueChars()\n",
|
" test = TestUniqueChars()\n",
|
||||||
" test.test_unique_chars(unique_chars)\n",
|
" unique_chars = UniqueChars()\n",
|
||||||
|
" test.test_unique_chars(unique_chars.has_unique_chars)\n",
|
||||||
" try:\n",
|
" try:\n",
|
||||||
" test.test_unique_chars(unique_chars_hash)\n",
|
" unique_chars_set = UniqueCharsSet()\n",
|
||||||
" test.test_unique_chars(unique_chars_inplace)\n",
|
" test.test_unique_chars(unique_chars_set.has_unique_chars)\n",
|
||||||
|
" unique_chars_in_place = UniqueCharsInPlace()\n",
|
||||||
|
" test.test_unique_chars(unique_chars_in_place.has_unique_chars)\n",
|
||||||
" except NameError:\n",
|
" except NameError:\n",
|
||||||
" # Alternate solutions are only defined\n",
|
" # Alternate solutions are only defined\n",
|
||||||
" # in the solutions file\n",
|
" # in the solutions file\n",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user