Skip to content

Instantly share code, notes, and snippets.

@zolotyh
Forked from andrewst/.dart
Last active December 1, 2018 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zolotyh/1c217d51ba5407e8dd6a521e2a3a9a46 to your computer and use it in GitHub Desktop.
Save zolotyh/1c217d51ba5407e8dd6a521e2a3a9a46 to your computer and use it in GitHub Desktop.
longestConsec
// Последовательные строки
// Задан массив строк и целое число k. Задача - вернуть самую длинную строку, состоящую из k последовательных строк, взятых в массиве.
// Пример:
// Входной массив: ['zone', 'abigail', 'theta', 'form', 'libe', 'zas', 'theta', 'abigail']
// Количество строк: 2
// Результат: 'abigailtheta'
String longestConsec(List<String> array, int k) {
return 'abigailtheta';
}
bool hasErrors = false;
List<String> messages = [];
void main() {
test('basic tests', () {
expect(longestConsec(['zone', 'abigail', 'theta', 'form', 'libe', 'zas'], 2), equals('abigailtheta'));
expect(longestConsec(['ejjjjmmtthh', 'zxxuueeg', 'aanlljrrrxx', 'dqqqaaabbb', 'oocccffuucccjjjkkkjyyyeehh'], 1), equals('oocccffuucccjjjkkkjyyyeehh'));
expect(longestConsec([], 3), equals(''));
expect(longestConsec(['itvayloxrp','wkppqsztdkmvcuwvereiupccauycnjutlv','vweqilsfytihvrzlaodfixoyxvyuyvgpck'], 2), equals('wkppqsztdkmvcuwvereiupccauycnjutlvvweqilsfytihvrzlaodfixoyxvyuyvgpck'));
expect(longestConsec(['wlwsasphmxx','owiaxujylentrklctozmymu','wpgozvxxiu'], 2), equals('wlwsasphmxxowiaxujylentrklctozmymu'));
expect(longestConsec(['zone', 'abigail', 'theta', 'form', 'libe', 'zas'], -2), equals(''));
expect(longestConsec(['it','wkppv','ixoyx', '3452', 'zzzzzzzzzzzz'], 3), equals('ixoyx3452zzzzzzzzzzzz'));
expect(longestConsec(['it','wkppv','ixoyx', '3452', 'zzzzzzzzzzzz'], 6), equals(''));
expect(longestConsec(['it','wkppv','ixoyx', '3452', 'zzzzzzzzzzzz'], 15), equals(''));
expect(longestConsec(['it','wkppv','ixoyx', '3452', 'zzzzzzzzzzzz'], 0), equals(''));
});
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