from calculator import add
def describe_string_calculator():
pass
def add(string):
pass
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def add(string):
return 0
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('1') == 1
def add(string):
return 1 if string else 0
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def add(string):
return int(string) if string else 0
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
def add(string):
if ',' in string:
return 3
return int(string) if string else 0
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def add(string):
if ',' in string:
return sum(map(int, string.split(',')))
return int(string) if string else 0
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def add(string):
if string:
return _add_numbers_in_string(string)
else:
return 0
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def add(string):
if '\n' in string;
return 3
if string:
return _add_numbers_in_string(string)
else:
return 0
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def add(string):
string = string.replace('\n', ',')
if string:
return _add_numbers_in_string(string)
else:
return 0
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
def add(string):
if string.startswith('//'):
return 3
string = string.replace('\n', ',')
if string:
return _add_numbers_in_string(string)
else:
return 0
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
def add(string):
if string.startswith('//'):
delimiter = string[2]
string = string[4:]
string = string.replace(delimiter, ',')
string = string.replace('\n', ',')
if string:
return _add_numbers_in_string(string)
else:
return 0
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
def add(string):
string = _normalize_delimiters(string)
if string:
return _add_numbers_in_string(string)
else:
return 0
def _normalize_delimiters(string):
if string.startswith('//'):
delimiter = string[2]
string = string[4:]
string = string.replace(delimiter, ',')
string = string.replace('\n', ',')
return string
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
def add(string):
string = _normalize_delimiters(string)
if string:
return _add_numbers_in_string(string)
else:
return 0
def _normalize_delimiters(string):
string = _normalize_custom_delimiter(string)
string = string.replace('\n', ',')
return string
def _normalize_custom_delimiter(string):
if string.startswith('//'):
delimiter = string[2]
string = string[4:]
string = string.replace(delimiter, ',')
return string
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
assert add('//abc\n1abc2abc3')
def can_be_mixed():
assert add('//;\n1,2;3\n4') == 10
def add(string):
string = _normalize_delimiters(string)
if string:
return _add_numbers_in_string(string)
else:
return 0
def _normalize_delimiters(string):
string = _normalize_custom_delimiter(string)
string = string.replace('\n', ',')
return string
def _normalize_custom_delimiter(string):
if string.startswith('//'):
delimiter_spec, string = string.split('\n', 1)
delimiter = delimiter_spec[2:]
string = string.replace(delimiter, ',')
return string
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
assert add('//abc\n1abc2abc3')
def can_be_mixed():
assert add('//;\n1,2;3\n4') == 10
def rejects_negative_numbers():
assert raises(ValueError, add, '-1')
def add(string):
if string.startswith('-'):
raise ValueError
string = _normalize_delimiters(string)
if string:
return _add_numbers_in_string(string)
else:
return 0
def _normalize_delimiters(string):
string = _normalize_custom_delimiter(string)
string = string.replace('\n', ',')
return string
def _normalize_custom_delimiter(string):
if string.startswith('//'):
delimiter_spec, string = string.split('\n', 1)
delimiter = delimiter_spec[2:]
string = string.replace(delimiter, ',')
return string
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
assert add('//abc\n1abc2abc3')
def can_be_mixed():
assert add('//;\n1,2;3\n4') == 10
def rejects_negative_numbers():
assert raises(ValueError, add, '-1')
assert raises(ValueError, add, '1,-2')
def add(string):
if '-' in string:
raise ValueError
string = _normalize_delimiters(string)
if string:
return _add_numbers_in_string(string)
else:
return 0
def _normalize_delimiters(string):
string = _normalize_custom_delimiter(string)
string = string.replace('\n', ',')
return string
def _normalize_custom_delimiter(string):
if string.startswith('//'):
delimiter_spec, string = string.split('\n', 1)
delimiter = delimiter_spec[2:]
string = string.replace(delimiter, ',')
return string
def _add_numbers_in_string(string):
return sum(map(int, string.split(',')))
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
assert add('//abc\n1abc2abc3')
def can_be_mixed():
assert add('//;\n1,2;3\n4') == 10
def can_be_minus_signs():
assert add('//-\n1-2') == 3
def rejects_negative_numbers():
assert raises(ValueError, add, '-1')
assert raises(ValueError, add, '1,-2')
def add(string):
string = _normalize_delimiters(string)
if string:
return _add_numbers_in_string(string)
else:
return 0
def _normalize_delimiters(string):
string = _normalize_custom_delimiter(string)
string = string.replace('\n', ',')
return string
def _normalize_custom_delimiter(string):
if string.startswith('//'):
delimiter_spec, string = string.split('\n', 1)
delimiter = delimiter_spec[2:]
string = string.replace(delimiter, ',')
return string
def _add_numbers_in_string(string):
numbers = map(int, string.split(','))
if any(number < 0 for number in numbers):
raise ValueError
return sum(numbers)
from calculator import add
def describe_string_calculator():
def returns_0_for_empty_string():
assert add('') == 0
def returns_bare_numbers():
assert add('0') == 0
assert add('1') == 1
def adds_numbers():
assert add('1,2') == 3
assert add('1,10') == 11
def describe_delimiters():
def can_be_newlines():
assert add('1\n2') == 3
def can_be_custom():
assert add('//;\n1;2') == 3
assert add('//+\n1+10') == 11
assert add('//abc\n1abc2abc3')
def can_be_mixed():
assert add('//;\n1,2;3\n4') == 10
def can_be_minus_signs():
assert add('//-\n1-2') == 3
def rejects_negative_numbers():
assert raises(ValueError, add, '-1')
assert raises(ValueError, add, '1,-2')
def add(string):
string = _normalize_delimiters(string)
if string:
return _add_numbers_in_string(string)
else:
return 0
def _normalize_delimiters(string):
string = _normalize_custom_delimiter(string)
string = string.replace('\n', ',')
return string
def _normalize_custom_delimiter(string):
if string.startswith('//'):
delimiter_spec, string = string.split('\n', 1)
delimiter = delimiter_spec[2:]
string = string.replace(delimiter, ',')
return string
def _add_numbers_in_string(string):
numbers = map(int, string.split(','))
_validate_numbers(numbers)
return sum(numbers)
def _validate_numbers(numbers):
if any(number < 0 for number in numbers):
raise ValueError