-
-
Save zolotyh/ba7b084623f05187a2a0fbc38da0970a 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
// Найдите самую длинную подстроку в алфавитном порядке. | |
// Например: самая длинная алфавитная подстрока в asdfaaaabbbbcttavvfffffdf является aaaabbbbctt. | |
// Входные параметры будут состоять только из символов нижнего регистра и будет содержать как минимум одну букву. | |
// Удачи :) | |
// P.S. Чтобы получить список символов в строке можно воспользоваться 'str.codeUnits' | |
// P.P.S Чтобы получить строку из символа можно вызвать String.fromCharCode(char), где char символ из str.codeUnits | |
String longest(String str) { | |
return 'abc'; | |
} | |
bool hasErrors = false; | |
List<String> messages = []; | |
void main() { | |
test('should work with single value', () { | |
expect(longest('z'), equals('z')); | |
}); | |
test('should work with different strings', () { | |
expect(longest('asdfaaaabbbbcttavvfffffdf'), equals('aaaabbbbctt')); | |
expect(longest('asd'), equals('as')); | |
expect(longest('nab'), equals('ab')); | |
expect(longest('abcdeapbcdef'), equals('abcde')); | |
expect(longest('asdfbyfgiklag'), equals('fgikl')); | |
expect(longest('zyba'), equals('z')); | |
expect(longest('aadcccvvvaaabb'), equals('cccvvv')); | |
}); | |
_longest(''); | |
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