代码拉取完成,页面将自动刷新
import unittest
class TestUserRegistration(unittest.TestCase):
def test_username_validation(self):
# Valid equivalence classes for username
valid_usernames = ["user123", "username", "testuser", "123456789012"]
# Invalid equivalence classes for username
invalid_usernames = ["u", "user1234567890", "username1234567890"]
for username in valid_usernames:
self.assertTrue(validate_username(username))
for username in invalid_usernames:
self.assertFalse(validate_username(username))
def test_password_validation(self):
# Valid equivalence classes for password
valid_passwords = ["Password1", "SecurePwd123", "12345678aA", "Abcdefg12345678"]
# Invalid equivalence classes for password
invalid_passwords = ["password", "12345678", "Abcdefghijklmnop", "12345678901234567"]
for password in valid_passwords:
self.assertTrue(validate_password(password))
for password in invalid_passwords:
self.assertFalse(validate_password(password))
# Function to validate username
def validate_username(username):
# Check if username length is between 6 to 12 characters
if 6 <= len(username) <= 12:
return True
else:
return False
# Function to validate password
def validate_password(password):
# Check if password length is between 8 to 16 characters
if not (8 <= len(password) <= 16):
return False
# Check if password contains both letters and numbers
has_digit = any(char.isdigit() for char in password)
has_alpha = any(char.isalpha() for char in password)
if has_digit and has_alpha:
return True
else:
return False
if __name__ == '__main__':
unittest.main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。