-
-
Save zolotyh/ce0e2addf3c50ea42327712a2f572701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Проверка пинкода | |
// Напиши фнукцию проверки пинкода. Пинкод может содержать 4 или 6 цифр. При правильном пинкоде нужно выводить true, при неправильном false | |
// Сделай так, чтобы прошли тесты | |
bool validatePIN(String input) { | |
return true; | |
} | |
bool hasErrors = false; | |
List<String> messages = []; | |
void main() { | |
test('should fail on wrong PIN', () { | |
expect(validatePIN("1"), equals(false)); | |
expect(validatePIN("12"), equals(false)); | |
expect(validatePIN("123"), equals(false)); | |
expect(validatePIN("12345"), equals(false)); | |
expect(validatePIN("1234567"), equals(false)); | |
expect(validatePIN("-1234"), equals(false)); | |
expect(validatePIN("1.234"), equals(false)); | |
expect(validatePIN("00000000"), equals(false)); | |
expect(validatePIN("a234"), equals(false)); | |
expect(validatePIN(".234"), equals(false)); | |
}); | |
test('should pass on valid PIN', () { | |
expect(validatePIN("1234"), equals(true)); | |
expect(validatePIN("0000"), equals(true)); | |
expect(validatePIN("1111"), equals(true)); | |
expect(validatePIN("123456"), equals(true)); | |
expect(validatePIN("098765"), equals(true)); | |
expect(validatePIN("000000"), equals(true)); | |
expect(validatePIN("123456"), equals(true)); | |
expect(validatePIN("090909"), equals(true)); | |
}); | |
if(!hasErrors ){ | |
print('💪Tests are passed! \n\n'); | |
} else { | |
print('💩 Tests aren\'t passed! \n\n'); | |
} | |
print(messages.join('\n')); | |
} | |
typedef bool Checker(dynamic input); | |
Checker equals(dynamic input) { | |
return (dynamic internalInput) { | |
input.toString() == internalInput.toString() | |
? true | |
: throw AssertionError('value: $input is not equal: $internalInput'); | |
}; | |
} | |
void test(String name, Function input) { | |
try { | |
input(); | |
messages.add('✓ $name'); | |
} catch (e) { | |
hasErrors = true; | |
if (e is AssertionError) { | |
messages.add('✗ $test failed \n name: $name\n exception: ${e.message}'); | |
} | |
} | |
} | |
void expect(dynamic input, bool validator(dynamic validatorInput)) { | |
validator(input); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment