Skip to content

Instantly share code, notes, and snippets.

@syberside
Last active November 29, 2018 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save syberside/80cb8c46778be04a7302cc9d95d8ea20 to your computer and use it in GitHub Desktop.
Save syberside/80cb8c46778be04a7302cc9d95d8ea20 to your computer and use it in GitHub Desktop.
Музей невероятно скучных вещей
List<int> removeSmallest(List<int> input){
if(input == null || input.length==0){
return input;
}
var minIndex = 0;
var min = input[0];
for(var i=1;i<input.length;i++){
var item = input[i];
if(item < min){
min = item;
minIndex = i;
}
}
var result = new List<int>(input.length-1);
var lastIndex = 0;
for(var i=0;i<input.length;i++){
if(i==minIndex){
continue;
}
result[lastIndex]=input[i];
lastIndex++;
}
//copyRange(result, 0, input, 0, minIndex);
//copyRange(result, minIndex+1, input, minIndex+1, input.length);
return result;
}
List<int> removeSmallest(List<int> input){
return [0];
}
bool hasErrors = false;
List<String> messages = [];
void main() {
test('[1, 2, 3, 4, 5]', () {
expect(removeSmallest([1, 2, 3, 4, 5]), equals([2, 3, 4, 5]));
});
test('[5, 3, 2, 1, 4]', () {
expect(removeSmallest([5, 3, 2, 1, 4]), equals([5, 3, 2, 4]));
});
test('[2, 2, 1, 2, 1]', () {
expect(removeSmallest([2, 2, 1, 2, 1]), equals([2, 2, 2, 1]));
});
test('[]', () {
expect(removeSmallest([]), equals([]));
});
test('null', () {
expect(removeSmallest(null), equals(null));
});
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