我寫了一個程序來檢查,如果字是等值線,但經過測試案例後,它說:「您的解決方案未能通過所有測試」檢查,如果一個字是等值線
下面是測試用例:
from unittest import TestCase
class IsogramTestCases(TestCase):
def test_checks_for_isograms(self):
word = 'abolishment'
self.assertEqual(
is_isogram(word),
(word, True),
msg="Isogram word, '{}' not detected correctly".format(word)
)
def test_returns_false_for_nonisograms(self):
word = 'alphabet'
self.assertEqual(
is_isogram(word),
(word, False),
msg="Non isogram word, '{}' falsely detected".format(word)
)
def test_it_only_accepts_strings(self):
with self.assertRaises(TypeError) as context:
is_isogram(2)
self.assertEqual(
'Argument should be a string',
context.exception.message,
'String inputs allowed only'
)
以下也是我的測試代碼。它通過了測試,但未能一些隱藏測試:
def is_isogram(word):
if type(word) == str or len(word) != 0:
if not word:
return (word, False)
word = word.lower()
return (word, len(set(word)) == len(word))
else:
raise TypeError('Argument should be a string')
有誰能夠告訴我什麼,我做錯了什麼?
什麼語言呢? –
它是Python語言 – Iakhator
找到我的答案[這裏](http://stackoverflow.com/questions/37924869/check-python-function-determine-isogram-from-codewars/43181468#43181468)如果這有幫助0123投票如果有幫助 –