Решение на Регулярни изрази от Драгомир Тунчев
Към профила на Драгомир Тунчев
Резултати
- 6 точки от тестове
- 0 бонус точки
- 6 точки общо
- 23 успешни тест(а)
- 16 неуспешни тест(а)
Код
Лог от изпълнението
...FF.F...F.F.FFF.....FF..FFF..F...F..F ====================================================================== FAIL: test_does_not_filter_invalid_emails (test.PrivacyFilterTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 48, in test_does_not_filter_invalid_emails self.assertEqual(text, solution.PrivacyFilter(text).filtered()) AssertionError: 'Contact me here: _invalid@email.com' != 'Contact me here: _[EMAIL]' - Contact me here: _invalid@email.com + Contact me here: _[EMAIL] ====================================================================== FAIL: test_does_not_filter_invalid_phone_numbers (test.PrivacyFilterTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 86, in test_does_not_filter_invalid_phone_numbers self.assertEqual(filtered, solution.PrivacyFilter(text).filtered()) AssertionError: '+1555 123, 55555' != '[PHONE], 55555' - +1555 123, 55555 + [PHONE], 55555 ====================================================================== FAIL: test_filters_whole_email_usernames_if_too_short (test.PrivacyFilterTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 61, in test_filters_whole_email_usernames_if_too_short self.assertEqual('[FILTERED]@example.com', self.partially_filter_email_usernames('me@example.com')) AssertionError: '[FILTERED]@example.com' != 'me@example.com' - [FILTERED]@example.com + me@example.com ====================================================================== FAIL: test_separates_preserved_country_code_from_filtered_phone_with_a_space (test.PrivacyFilterTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 100, in test_separates_preserved_country_code_from_filtered_phone_with_a_space self.assertEqual(filtered, filter.filtered()) AssertionError: 'Phone: 0025 [FILTERED]' != 'Phone: [FILTERED]5' - Phone: 0025 [FILTERED] ? ----- + Phone: [FILTERED]5 ? + ====================================================================== FAIL: test_allows_huge_years_in_date_validation (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 246, in test_allows_huge_years_in_date_validation self.assertTrue(solution.Validations.is_date('9999-01-01')) AssertionError: None is not true ====================================================================== FAIL: test_allows_zero_years_in_date_validation (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 243, in test_allows_zero_years_in_date_validation self.assertTrue(solution.Validations.is_date('0000-01-01')) AssertionError: None is not true ====================================================================== FAIL: test_can_validate_more_complex_emails (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 124, in test_can_validate_more_complex_emails self.assertIs(solution.Validations.is_email(email), valid) AssertionError: <_sre.SRE_Match object at 0xb781d8b8> is not True ====================================================================== FAIL: test_can_validate_more_complex_phone_numbers (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 160, in test_can_validate_more_complex_phone_numbers self.assertIs(solution.Validations.is_phone(phone), valid) AssertionError: None is not False ====================================================================== FAIL: test_handles_multiline_strings_in_IP_validation_properly (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 189, in test_handles_multiline_strings_in_IP_validation_properly self.assertFalse(solution.Validations.is_ip_address("8.8.8.8\n")) AssertionError: <_sre.SRE_Match object at 0xb781d910> is not false ====================================================================== FAIL: test_handles_multiline_strings_in_hostname_validation_properly (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 179, in test_handles_multiline_strings_in_hostname_validation_properly self.assertFalse(solution.Validations.is_hostname("foo.com\n")) AssertionError: <_sre.SRE_Match object at 0xb7832070> is not false ====================================================================== FAIL: test_handles_newlines_in_date_validation (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 259, in test_handles_newlines_in_date_validation self.assertFalse(solution.Validations.is_date("2012-11-19\n")) AssertionError: <_sre.SRE_Match object at 0xb7837188> is not false ====================================================================== FAIL: test_handles_newlines_in_time_and_datetime_validation (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 288, in test_handles_newlines_in_time_and_datetime_validation self.assertFalse(solution.Validations.is_time("12:01:01\n")) AssertionError: <_sre.SRE_Match object at 0xb781f5a0> is not false ====================================================================== FAIL: test_returns_boolean_True_or_False (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 109, in test_returns_boolean_True_or_False self.assertIs(solution.Validations.is_email('foo@bar.com'), True) AssertionError: <_sre.SRE_Match object at 0xb781d968> is not True ====================================================================== FAIL: test_validates_datetime_values (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 280, in test_validates_datetime_values self.assertTrue(solution.Validations.is_datetime('9999-11-19T23:59:00')) AssertionError: None is not true ====================================================================== FAIL: test_validates_more_complex_numbers (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 205, in test_validates_more_complex_numbers self.assertFalse(solution.Validations.is_number('00')) AssertionError: <_sre.SRE_Match object at 0xb781cc80> is not false ====================================================================== FAIL: test_validates_times (test.ValidationsTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "lib/language/python/runner.py", line 60, in thread raise it.exc_info[1] File "lib/language/python/runner.py", line 48, in run self.result = func(*args, **kwargs) File "/tmp/d20140513-11348-hni5g4/test.py", line 266, in test_validates_times self.assertTrue(solution.Validations.is_time('23:59:59')) AssertionError: None is not true ---------------------------------------------------------------------- Ran 39 tests in 0.069s FAILED (failures=16)
История (21 версии и 4 коментара)
Драгомир обнови решението на 16.04.2014 03:08 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 03:28 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 15:12 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 15:20 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 16:47 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 16:48 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 16:54 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 17:17 (преди над 10 години)
Драгомир обнови решението на 16.04.2014 20:54 (преди над 10 години)
Използваш един и същ регулярен израз на няколко места. Искаш да го изнесеш като константа :)
Опрости малко
filtered
метода. Станал е огромен с много if-elif-elif-... Напълно в реда на нещата е да си дефинираш няколко protected метода, които да вършат мръсната работа иfiltered
само да решава кой от тях да извикаВ условието на задачата пише, методите в
Validations
да са класови, не статични
Драгомир обнови решението на 18.04.2014 15:42 (преди над 10 години)
Драгомир обнови решението на 18.04.2014 15:47 (преди над 10 години)
Драгомир обнови решението на 18.04.2014 16:36 (преди над 10 години)
Може ли някаква подсказка за международния код? Не виждам как мога да го направя да разпознава, че +359 е кода, а не +3 или +35, за примерно +359123456789. При +3 има точно 11 цифри, при +35 са 10, при +359, съответно 9, и трите случая отговарят на Същинска част: от 6 до 11 цифри.
Единственото, което ми идва на ум е да се проверят всички валидни международни кодове и да се сложат в един регулярен израз, който да разпознава само тях, но все си мисля, че трябва да има и по-лесен начин?
Драгомир обнови решението на 18.04.2014 18:50 (преди над 10 години)
Драгомир обнови решението на 18.04.2014 18:54 (преди над 10 години)
Драгомир обнови решението на 18.04.2014 19:09 (преди над 10 години)
В +359 888 111 222
международният код е +359. В +35 9888 111 222
международният код е +35
. Така по-ясно ли е?
Не изреждай всички валидни кодове на държави, а си придържай само към нашите изисквания.
С други думи, ако нямаме разделител, приемаме, че кодът е 3 цифри?