Skip to content

Instantly share code, notes, and snippets.

@zolotyh
Forked from NevRA/highAndLow.dart
Last active December 1, 2018 10:07
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/b3cedc7a57c020b960330206e3ac9d14 to your computer and use it in GitHub Desktop.
Save zolotyh/b3cedc7a57c020b960330206e3ac9d14 to your computer and use it in GitHub Desktop.
// Наименьшее и наибольшее
// В этом маленьком задании вам предоставляется строка разделенных пробелами чисел и приходится возвращать самое большой и самое маленькое число в виде строки.
// Пример
// highAndLow("1 2 3 4 5"); // return "5 1"
// highAndLow("1 2 -3 4 5"); // return "5 -3"
// highAndLow("1 9 3 4 -5"); // return "9 -5"
import 'dart:math';
String highAndLow(String input) {
int minValue = 42;
int maxValue = 43;
return '$maxValue $minValue';
}
bool hasErrors = false;
List<String> messages = [];
void main() {
test('should work with single value', () {
expect(highAndLow('0'), equals('0 0'));
});
test('should work with two equal values', () {
expect(highAndLow('42 42'), equals('42 42'));
});
test('should work with different values', () {
expect(highAndLow('1 2 3 4 5'), equals('5 1'));
});
test('should work with negative values', () {
expect(highAndLow('1 2 -3 4 5'), equals('5 -3'));
expect(highAndLow('1 9 3 4 -5'), equals('9 -5'));
});
test('should work when all values negative', () {
expect(highAndLow('-1 -2 -3 -4 -5'), equals('-1 -5'));
});
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