diff --git a/.gitignore b/.gitignore index 9ef62e5ff..d2dad3e47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ __pycache__/ -tape.py -test/ -pytest.ini -website/ \ No newline at end of file +website/ +ms.py +tape* \ No newline at end of file diff --git a/confg.ini b/confg.ini new file mode 100644 index 000000000..e8cde1dd7 --- /dev/null +++ b/confg.ini @@ -0,0 +1,2 @@ +[tape] +python_files=*.test.py \ No newline at end of file diff --git a/scripts/tdd.py b/scripts/tdd.py index f1cfc5274..e1accfcca 100644 --- a/scripts/tdd.py +++ b/scripts/tdd.py @@ -10,15 +10,15 @@ for snippet in snippets: content = f.read() code = re.search(codeRe,content).group(1).strip() file_to_write_to = open(f'test/{snippet}/{snippet}.py','w') - test_file = open(f'test/{snippet}/{snippet}_test.py','w') + test_file = open(f'test/{snippet}/{snippet}.test.py','w') file_to_write_to.write(code) file_to_write_to.close() - test_file.write(''' + test_file.write(f''' import types,functools from tape import test from {snippet} import {snippet} def {snippet}_test(t): t.true(isinstance({snippet}, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'{snippet} is a function') test('Testing {snippet}',{snippet}_test) - '''.format(snippet = snippet).strip()) + '''.strip()) test_file.close() \ No newline at end of file diff --git a/test/average/average.py b/test/average/average.py new file mode 100644 index 000000000..1ff6e2ef9 --- /dev/null +++ b/test/average/average.py @@ -0,0 +1,2 @@ +def average(*args): + return sum(args, 0.0) / len(args) \ No newline at end of file diff --git a/test/average/average.test.py b/test/average/average.test.py new file mode 100644 index 000000000..39c275cbd --- /dev/null +++ b/test/average/average.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from average import average +def average_test(t): + t.true(isinstance(average, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'average is a function') +test('Testing average',average_test) \ No newline at end of file diff --git a/test/byte_size/byte_size.py b/test/byte_size/byte_size.py new file mode 100644 index 000000000..5050bb37d --- /dev/null +++ b/test/byte_size/byte_size.py @@ -0,0 +1,2 @@ +def byte_size(string): + return(len(string.encode('utf-8'))) \ No newline at end of file diff --git a/test/byte_size/byte_size.test.py b/test/byte_size/byte_size.test.py new file mode 100644 index 000000000..99eb8a5d1 --- /dev/null +++ b/test/byte_size/byte_size.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from byte_size import byte_size +def byte_size_test(t): + t.true(isinstance(byte_size, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'byte_size is a function') +test('Testing byte_size',byte_size_test) \ No newline at end of file diff --git a/test/capitalize/capitalize.py b/test/capitalize/capitalize.py new file mode 100644 index 000000000..0eb21baa1 --- /dev/null +++ b/test/capitalize/capitalize.py @@ -0,0 +1,2 @@ +def capitalize(string, lower_rest=False): + return string[:1].upper() + (string[1:].lower() if lower_rest else string[1:]) \ No newline at end of file diff --git a/test/capitalize/capitalize.test.py b/test/capitalize/capitalize.test.py new file mode 100644 index 000000000..aa1b73422 --- /dev/null +++ b/test/capitalize/capitalize.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from capitalize import capitalize +def capitalize_test(t): + t.true(isinstance(capitalize, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'capitalize is a function') +test('Testing capitalize',capitalize_test) \ No newline at end of file diff --git a/test/capitalize_every_word/capitalize_every_word.py b/test/capitalize_every_word/capitalize_every_word.py new file mode 100644 index 000000000..7f7d7bf5a --- /dev/null +++ b/test/capitalize_every_word/capitalize_every_word.py @@ -0,0 +1,2 @@ +def capitalize_every_word(string): + return string.title() \ No newline at end of file diff --git a/test/capitalize_every_word/capitalize_every_word.test.py b/test/capitalize_every_word/capitalize_every_word.test.py new file mode 100644 index 000000000..951367deb --- /dev/null +++ b/test/capitalize_every_word/capitalize_every_word.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from capitalize_every_word import capitalize_every_word +def capitalize_every_word_test(t): + t.true(isinstance(capitalize_every_word, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'capitalize_every_word is a function') +test('Testing capitalize_every_word',capitalize_every_word_test) \ No newline at end of file diff --git a/test/chunk/chunk.py b/test/chunk/chunk.py new file mode 100644 index 000000000..6f247c2c9 --- /dev/null +++ b/test/chunk/chunk.py @@ -0,0 +1,7 @@ +from math import ceil + + +def chunk(arr, size): + return list( + map(lambda x: arr[x * size:x * size + size], + list(range(0, ceil(len(arr) / size))))) \ No newline at end of file diff --git a/test/chunk/chunk.test.py b/test/chunk/chunk.test.py new file mode 100644 index 000000000..d379a9fda --- /dev/null +++ b/test/chunk/chunk.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from chunk import chunk +def chunk_test(t): + t.true(isinstance(chunk, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'chunk is a function') +test('Testing chunk',chunk_test) \ No newline at end of file diff --git a/test/compact/compact.py b/test/compact/compact.py new file mode 100644 index 000000000..f90cc92d7 --- /dev/null +++ b/test/compact/compact.py @@ -0,0 +1,2 @@ +def compact(arr): + return list(filter(lambda x: bool(x), arr)) \ No newline at end of file diff --git a/test/compact/compact.test.py b/test/compact/compact.test.py new file mode 100644 index 000000000..648f43cae --- /dev/null +++ b/test/compact/compact.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from compact import compact +def compact_test(t): + t.true(isinstance(compact, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'compact is a function') +test('Testing compact',compact_test) \ No newline at end of file diff --git a/test/count_by/count_by.py b/test/count_by/count_by.py new file mode 100644 index 000000000..aae034ead --- /dev/null +++ b/test/count_by/count_by.py @@ -0,0 +1,6 @@ +def count_by(arr, fn=lambda x: x): + key = {} + for el in map(fn, arr): + key[el] = 0 if not el in key else key[el] + key[el] += 1 + return key \ No newline at end of file diff --git a/test/count_by/count_by.test.py b/test/count_by/count_by.test.py new file mode 100644 index 000000000..38648c04f --- /dev/null +++ b/test/count_by/count_by.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from count_by import count_by +def count_by_test(t): + t.true(isinstance(count_by, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'count_by is a function') +test('Testing count_by',count_by_test) \ No newline at end of file diff --git a/test/count_occurences/count_occurences.py b/test/count_occurences/count_occurences.py new file mode 100644 index 000000000..161f8f86f --- /dev/null +++ b/test/count_occurences/count_occurences.py @@ -0,0 +1,4 @@ +def count_occurences(arr, val): + return reduce( + (lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0), + arr) \ No newline at end of file diff --git a/test/count_occurences/count_occurences.test.py b/test/count_occurences/count_occurences.test.py new file mode 100644 index 000000000..b1290e7f6 --- /dev/null +++ b/test/count_occurences/count_occurences.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from count_occurences import count_occurences +def count_occurences_test(t): + t.true(isinstance(count_occurences, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'count_occurences is a function') +test('Testing count_occurences',count_occurences_test) \ No newline at end of file diff --git a/test/count_vowels/count_vowels.py b/test/count_vowels/count_vowels.py new file mode 100644 index 000000000..05217ac13 --- /dev/null +++ b/test/count_vowels/count_vowels.py @@ -0,0 +1,5 @@ +import re + + +def count_vowels(str): + return len(len(re.findall(r'[aeiou]', str, re.IGNORECASE))) \ No newline at end of file diff --git a/test/count_vowels/count_vowels.test.py b/test/count_vowels/count_vowels.test.py new file mode 100644 index 000000000..d83e4566f --- /dev/null +++ b/test/count_vowels/count_vowels.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from count_vowels import count_vowels +def count_vowels_test(t): + t.true(isinstance(count_vowels, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'count_vowels is a function') +test('Testing count_vowels',count_vowels_test) \ No newline at end of file diff --git a/test/decapitalize/decapitalize.py b/test/decapitalize/decapitalize.py new file mode 100644 index 000000000..4518a6599 --- /dev/null +++ b/test/decapitalize/decapitalize.py @@ -0,0 +1,2 @@ +def decapitalize(string, upper_rest=False): + return str[:1].lower() + (str[1:].upper() if upper_rest else str[1:]) \ No newline at end of file diff --git a/test/decapitalize/decapitalize.test.py b/test/decapitalize/decapitalize.test.py new file mode 100644 index 000000000..6bacbffad --- /dev/null +++ b/test/decapitalize/decapitalize.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from decapitalize import decapitalize +def decapitalize_test(t): + t.true(isinstance(decapitalize, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'decapitalize is a function') +test('Testing decapitalize',decapitalize_test) \ No newline at end of file diff --git a/test/deep_flatten/deep_flatten.py b/test/deep_flatten/deep_flatten.py new file mode 100644 index 000000000..355991028 --- /dev/null +++ b/test/deep_flatten/deep_flatten.py @@ -0,0 +1,15 @@ +def spread(arg): + ret = [] + for i in arg: + if isinstance(i, list): + ret.extend(i) + else: + ret.append(i) + return ret + + +def deep_flatten(arr): + result = [] + result.extend( + spread(list(map(lambda x: deep(x) if type(x) == list else x, arr)))) + return result \ No newline at end of file diff --git a/test/deep_flatten/deep_flatten.test.py b/test/deep_flatten/deep_flatten.test.py new file mode 100644 index 000000000..2479bc283 --- /dev/null +++ b/test/deep_flatten/deep_flatten.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from deep_flatten import deep_flatten +def deep_flatten_test(t): + t.true(isinstance(deep_flatten, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'deep_flatten is a function') +test('Testing deep_flatten',deep_flatten_test) \ No newline at end of file diff --git a/test/difference/difference.py b/test/difference/difference.py new file mode 100644 index 000000000..b375d7748 --- /dev/null +++ b/test/difference/difference.py @@ -0,0 +1,3 @@ +def difference(a, b): + b = set(b) + return [item for item in a if item not in b] \ No newline at end of file diff --git a/test/difference/difference.test.py b/test/difference/difference.test.py new file mode 100644 index 000000000..424fff1b3 --- /dev/null +++ b/test/difference/difference.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from difference import difference +def difference_test(t): + t.true(isinstance(difference, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'difference is a function') +test('Testing difference',difference_test) \ No newline at end of file diff --git a/test/difference_by/difference_by.py b/test/difference_by/difference_by.py new file mode 100644 index 000000000..fb639d430 --- /dev/null +++ b/test/difference_by/difference_by.py @@ -0,0 +1,3 @@ +def difference_by(a, b, fn): + b = set(map(fn, b)) + return [item for item in a if fn(item) not in b] \ No newline at end of file diff --git a/test/difference_by/difference_by.test.py b/test/difference_by/difference_by.test.py new file mode 100644 index 000000000..62e02d2ea --- /dev/null +++ b/test/difference_by/difference_by.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from difference_by import difference_by +def difference_by_test(t): + t.true(isinstance(difference_by, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'difference_by is a function') +test('Testing difference_by',difference_by_test) \ No newline at end of file diff --git a/test/factorial/factorial.py b/test/factorial/factorial.py new file mode 100644 index 000000000..999f1fb52 --- /dev/null +++ b/test/factorial/factorial.py @@ -0,0 +1,5 @@ +def factorial(num): + if not ((num >= 0) & (num % 1 == 0)): + raise Exception( + f"Number( {num} ) can't be floating point or negative ") + return 1 if num == 0 else num * factorial(num - 1) \ No newline at end of file diff --git a/test/factorial/factorial.test.py b/test/factorial/factorial.test.py new file mode 100644 index 000000000..73e3fbd9f --- /dev/null +++ b/test/factorial/factorial.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from factorial import factorial +def factorial_test(t): + t.true(isinstance(factorial, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'factorial is a function') +test('Testing factorial',factorial_test) \ No newline at end of file diff --git a/test/gcd/gcd.py b/test/gcd/gcd.py new file mode 100644 index 000000000..a4ad73048 --- /dev/null +++ b/test/gcd/gcd.py @@ -0,0 +1,21 @@ +from functools import reduce + + +def spread(arg): + ret = [] + for i in arg: + if isinstance(i, list): + ret.extend(i) + else: + ret.append(i) + return ret + + +def gcd(*args): + numbers = [] + numbers.extend(spread(list(args))) + + def _gcd(x, y): + return x if not y else gcd(y, x % y) + + return reduce((lambda x, y: _gcd(x, y)), numbers) \ No newline at end of file diff --git a/test/gcd/gcd.test.py b/test/gcd/gcd.test.py new file mode 100644 index 000000000..a89167edb --- /dev/null +++ b/test/gcd/gcd.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from gcd import gcd +def gcd_test(t): + t.true(isinstance(gcd, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'gcd is a function') +test('Testing gcd',gcd_test) \ No newline at end of file diff --git a/test/is_lower_case/is_lower_case.py b/test/is_lower_case/is_lower_case.py new file mode 100644 index 000000000..3b914e8b9 --- /dev/null +++ b/test/is_lower_case/is_lower_case.py @@ -0,0 +1,2 @@ +def is_lower_case(str): + return str == str.lower() \ No newline at end of file diff --git a/test/is_lower_case/is_lower_case.test.py b/test/is_lower_case/is_lower_case.test.py new file mode 100644 index 000000000..52bb63d17 --- /dev/null +++ b/test/is_lower_case/is_lower_case.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from is_lower_case import is_lower_case +def is_lower_case_test(t): + t.true(isinstance(is_lower_case, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'is_lower_case is a function') +test('Testing is_lower_case',is_lower_case_test) \ No newline at end of file diff --git a/test/is_upper_case/is_upper_case.py b/test/is_upper_case/is_upper_case.py new file mode 100644 index 000000000..062b4f8d2 --- /dev/null +++ b/test/is_upper_case/is_upper_case.py @@ -0,0 +1,2 @@ +def is_upper_case(str): + return str == str.upper() \ No newline at end of file diff --git a/test/is_upper_case/is_upper_case.test.py b/test/is_upper_case/is_upper_case.test.py new file mode 100644 index 000000000..9c834b63b --- /dev/null +++ b/test/is_upper_case/is_upper_case.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from is_upper_case import is_upper_case +def is_upper_case_test(t): + t.true(isinstance(is_upper_case, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'is_upper_case is a function') +test('Testing is_upper_case',is_upper_case_test) \ No newline at end of file diff --git a/test/lcm/lcm.py b/test/lcm/lcm.py new file mode 100644 index 000000000..bd6cf9111 --- /dev/null +++ b/test/lcm/lcm.py @@ -0,0 +1,24 @@ +from functools import reduce + + +def spread(arg): + ret = [] + for i in arg: + if isinstance(i, list): + ret.extend(i) + else: + ret.append(i) + return ret + + +def lcm(*args): + numbers = [] + numbers.extend(spread(list(args))) + + def _gcd(x, y): + return x if not y else gcd(y, x % y) + + def _lcm(x, y): + return x * y / _gcd(x, y) + + return reduce((lambda x, y: _lcm(x, y)), numbers) \ No newline at end of file diff --git a/test/lcm/lcm.test.py b/test/lcm/lcm.test.py new file mode 100644 index 000000000..79e027d86 --- /dev/null +++ b/test/lcm/lcm.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from lcm import lcm +def lcm_test(t): + t.true(isinstance(lcm, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'lcm is a function') +test('Testing lcm',lcm_test) \ No newline at end of file diff --git a/test/max_n/max_n.py b/test/max_n/max_n.py new file mode 100644 index 000000000..70006802c --- /dev/null +++ b/test/max_n/max_n.py @@ -0,0 +1,8 @@ +from copy import deepcopy + + +def max_n(arr, n=1): + numbers = deepcopy(arr) + numbers.sort() + numbers.reverse() + return numbers[:n] \ No newline at end of file diff --git a/test/max_n/max_n.test.py b/test/max_n/max_n.test.py new file mode 100644 index 000000000..6040310e7 --- /dev/null +++ b/test/max_n/max_n.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from max_n import max_n +def max_n_test(t): + t.true(isinstance(max_n, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'max_n is a function') +test('Testing max_n',max_n_test) \ No newline at end of file diff --git a/test/min_n/min_n.py b/test/min_n/min_n.py new file mode 100644 index 000000000..c973b3a61 --- /dev/null +++ b/test/min_n/min_n.py @@ -0,0 +1,7 @@ +from copy import deepcopy + + +def min_n(arr, n=1): + numbers = deepcopy(arr) + numbers.sort() + return numbers[:n] \ No newline at end of file diff --git a/test/min_n/min_n.test.py b/test/min_n/min_n.test.py new file mode 100644 index 000000000..5ad3eb1d0 --- /dev/null +++ b/test/min_n/min_n.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from min_n import min_n +def min_n_test(t): + t.true(isinstance(min_n, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'min_n is a function') +test('Testing min_n',min_n_test) \ No newline at end of file diff --git a/test/palindrome/palindrome.py b/test/palindrome/palindrome.py new file mode 100644 index 000000000..f7b5165e7 --- /dev/null +++ b/test/palindrome/palindrome.py @@ -0,0 +1,4 @@ +def palindrome(string): + from re import sub + s = sub('[\W_]', '', string.lower()) + return s == s[::-1] \ No newline at end of file diff --git a/test/palindrome/palindrome.test.py b/test/palindrome/palindrome.test.py new file mode 100644 index 000000000..863a2d3d2 --- /dev/null +++ b/test/palindrome/palindrome.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from palindrome import palindrome +def palindrome_test(t): + t.true(isinstance(palindrome, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'palindrome is a function') +test('Testing palindrome',palindrome_test) \ No newline at end of file diff --git a/test/shuffle/shuffle.py b/test/shuffle/shuffle.py new file mode 100644 index 000000000..2d16df93f --- /dev/null +++ b/test/shuffle/shuffle.py @@ -0,0 +1,12 @@ +from copy import deepcopy +from random import randint + + +def shuffle(arr): + temp_arr = deepcopy(arr) + m = len(temp_arr) + while (m): + m -= 1 + i = randint(0, m) + temp_arr[m], temp_arr[i] = temp_arr[i], temp_arr[m] + return temp_arr \ No newline at end of file diff --git a/test/shuffle/shuffle.test.py b/test/shuffle/shuffle.test.py new file mode 100644 index 000000000..2bb757cb1 --- /dev/null +++ b/test/shuffle/shuffle.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from shuffle import shuffle +def shuffle_test(t): + t.true(isinstance(shuffle, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'shuffle is a function') +test('Testing shuffle',shuffle_test) \ No newline at end of file diff --git a/test/spread/spread.py b/test/spread/spread.py new file mode 100644 index 000000000..02baa7f82 --- /dev/null +++ b/test/spread/spread.py @@ -0,0 +1,8 @@ +def spread(arg): + ret = [] + for i in arg: + if isinstance(i, list): + ret.extend(i) + else: + ret.append(i) + return ret \ No newline at end of file diff --git a/test/spread/spread.test.py b/test/spread/spread.test.py new file mode 100644 index 000000000..dc8e035c1 --- /dev/null +++ b/test/spread/spread.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from spread import spread +def spread_test(t): + t.true(isinstance(spread, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'spread is a function') +test('Testing spread',spread_test) \ No newline at end of file diff --git a/test/zip/zip.py b/test/zip/zip.py new file mode 100644 index 000000000..ef9aa5593 --- /dev/null +++ b/test/zip/zip.py @@ -0,0 +1,8 @@ +def zip(*args, fillvalue=None): + max_length = max([len(arr) for arr in args]) + result = [] + for i in range(max_length): + result.append([ + args[k][i] if i < len(args[k]) else None for k in range(len(args)) + ]) + return result \ No newline at end of file diff --git a/test/zip/zip.test.py b/test/zip/zip.test.py new file mode 100644 index 000000000..c5ad71b56 --- /dev/null +++ b/test/zip/zip.test.py @@ -0,0 +1,6 @@ +import types,functools +from tape import test +from zip import zip +def zip_test(t): + t.true(isinstance(zip, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'zip is a function') +test('Testing zip',zip_test) \ No newline at end of file