Skip to content

Instantly share code, notes, and snippets.

@zolotyh
Forked from NevRA/uniqueInOrder.dart
Last active December 1, 2018 09:51
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/9a5060c7d730a3d1b4abe82f90d86796 to your computer and use it in GitHub Desktop.
Save zolotyh/9a5060c7d730a3d1b4abe82f90d86796 to your computer and use it in GitHub Desktop.
// Уникальный порядок
// Реализуй функцию, которая принимает в качестве аргумента массив элементов и возвращает массив элементов без каких-либо элементов с одинаковым значением рядом друг с другом и сохраняя исходный порядок
// uniqueInOrder([1,2,2,3,3,2,2,1]) ==> [1,2,3,2,1]
// Сделай так, чтобы прошли тесты
Iterable<int> uniqueInOrder(List<int> array) {
return [1, 2];
}
bool hasErrors = false;
List<String> messages = [];
void main() {
test('should pass test cases', () {
expect(uniqueInOrder([1, 2, 2, 3, 3]), equals([1, 2, 3]));
expect(uniqueInOrder([7, 7, 3, 1, 2, 7]), equals([7, 3, 1, 2, 7]));
expect(uniqueInOrder([-1, 0, 0, -1]), equals([-1, 0, -1]));
expect(uniqueInOrder([5]), equals([5]));
expect(uniqueInOrder([5, 5]), equals([5]));
expect(uniqueInOrder([1, 2, 3, 3, 4, 3, 3, 4, 0]), equals([1, 2, 3, 4, 3, 4, 0]));
expect(uniqueInOrder([1, 2, 3, 3, 1, 3, 6, 5, 4, 2, 3]), equals([1, 2, 3, 1, 3, 6, 5, 4, 2, 3]));
});
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