Add lots of things(including tests)
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
__pycache__/
|
||||
tape.py
|
||||
test/
|
||||
pytest.ini
|
||||
website/
|
||||
ms.py
|
||||
tape*
|
||||
@ -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()
|
||||
2
test/average/average.py
Normal file
2
test/average/average.py
Normal file
@ -0,0 +1,2 @@
|
||||
def average(*args):
|
||||
return sum(args, 0.0) / len(args)
|
||||
6
test/average/average.test.py
Normal file
6
test/average/average.test.py
Normal file
@ -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)
|
||||
2
test/byte_size/byte_size.py
Normal file
2
test/byte_size/byte_size.py
Normal file
@ -0,0 +1,2 @@
|
||||
def byte_size(string):
|
||||
return(len(string.encode('utf-8')))
|
||||
6
test/byte_size/byte_size.test.py
Normal file
6
test/byte_size/byte_size.test.py
Normal file
@ -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)
|
||||
2
test/capitalize/capitalize.py
Normal file
2
test/capitalize/capitalize.py
Normal file
@ -0,0 +1,2 @@
|
||||
def capitalize(string, lower_rest=False):
|
||||
return string[:1].upper() + (string[1:].lower() if lower_rest else string[1:])
|
||||
6
test/capitalize/capitalize.test.py
Normal file
6
test/capitalize/capitalize.test.py
Normal file
@ -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)
|
||||
2
test/capitalize_every_word/capitalize_every_word.py
Normal file
2
test/capitalize_every_word/capitalize_every_word.py
Normal file
@ -0,0 +1,2 @@
|
||||
def capitalize_every_word(string):
|
||||
return string.title()
|
||||
6
test/capitalize_every_word/capitalize_every_word.test.py
Normal file
6
test/capitalize_every_word/capitalize_every_word.test.py
Normal file
@ -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)
|
||||
7
test/chunk/chunk.py
Normal file
7
test/chunk/chunk.py
Normal file
@ -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)))))
|
||||
6
test/chunk/chunk.test.py
Normal file
6
test/chunk/chunk.test.py
Normal file
@ -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)
|
||||
2
test/compact/compact.py
Normal file
2
test/compact/compact.py
Normal file
@ -0,0 +1,2 @@
|
||||
def compact(arr):
|
||||
return list(filter(lambda x: bool(x), arr))
|
||||
6
test/compact/compact.test.py
Normal file
6
test/compact/compact.test.py
Normal file
@ -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)
|
||||
6
test/count_by/count_by.py
Normal file
6
test/count_by/count_by.py
Normal file
@ -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
|
||||
6
test/count_by/count_by.test.py
Normal file
6
test/count_by/count_by.test.py
Normal file
@ -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)
|
||||
4
test/count_occurences/count_occurences.py
Normal file
4
test/count_occurences/count_occurences.py
Normal file
@ -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)
|
||||
6
test/count_occurences/count_occurences.test.py
Normal file
6
test/count_occurences/count_occurences.test.py
Normal file
@ -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)
|
||||
5
test/count_vowels/count_vowels.py
Normal file
5
test/count_vowels/count_vowels.py
Normal file
@ -0,0 +1,5 @@
|
||||
import re
|
||||
|
||||
|
||||
def count_vowels(str):
|
||||
return len(len(re.findall(r'[aeiou]', str, re.IGNORECASE)))
|
||||
6
test/count_vowels/count_vowels.test.py
Normal file
6
test/count_vowels/count_vowels.test.py
Normal file
@ -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)
|
||||
2
test/decapitalize/decapitalize.py
Normal file
2
test/decapitalize/decapitalize.py
Normal file
@ -0,0 +1,2 @@
|
||||
def decapitalize(string, upper_rest=False):
|
||||
return str[:1].lower() + (str[1:].upper() if upper_rest else str[1:])
|
||||
6
test/decapitalize/decapitalize.test.py
Normal file
6
test/decapitalize/decapitalize.test.py
Normal file
@ -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)
|
||||
15
test/deep_flatten/deep_flatten.py
Normal file
15
test/deep_flatten/deep_flatten.py
Normal file
@ -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
|
||||
6
test/deep_flatten/deep_flatten.test.py
Normal file
6
test/deep_flatten/deep_flatten.test.py
Normal file
@ -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)
|
||||
3
test/difference/difference.py
Normal file
3
test/difference/difference.py
Normal file
@ -0,0 +1,3 @@
|
||||
def difference(a, b):
|
||||
b = set(b)
|
||||
return [item for item in a if item not in b]
|
||||
6
test/difference/difference.test.py
Normal file
6
test/difference/difference.test.py
Normal file
@ -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)
|
||||
3
test/difference_by/difference_by.py
Normal file
3
test/difference_by/difference_by.py
Normal file
@ -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]
|
||||
6
test/difference_by/difference_by.test.py
Normal file
6
test/difference_by/difference_by.test.py
Normal file
@ -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)
|
||||
5
test/factorial/factorial.py
Normal file
5
test/factorial/factorial.py
Normal file
@ -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)
|
||||
6
test/factorial/factorial.test.py
Normal file
6
test/factorial/factorial.test.py
Normal file
@ -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)
|
||||
21
test/gcd/gcd.py
Normal file
21
test/gcd/gcd.py
Normal file
@ -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)
|
||||
6
test/gcd/gcd.test.py
Normal file
6
test/gcd/gcd.test.py
Normal file
@ -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)
|
||||
2
test/is_lower_case/is_lower_case.py
Normal file
2
test/is_lower_case/is_lower_case.py
Normal file
@ -0,0 +1,2 @@
|
||||
def is_lower_case(str):
|
||||
return str == str.lower()
|
||||
6
test/is_lower_case/is_lower_case.test.py
Normal file
6
test/is_lower_case/is_lower_case.test.py
Normal file
@ -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)
|
||||
2
test/is_upper_case/is_upper_case.py
Normal file
2
test/is_upper_case/is_upper_case.py
Normal file
@ -0,0 +1,2 @@
|
||||
def is_upper_case(str):
|
||||
return str == str.upper()
|
||||
6
test/is_upper_case/is_upper_case.test.py
Normal file
6
test/is_upper_case/is_upper_case.test.py
Normal file
@ -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)
|
||||
24
test/lcm/lcm.py
Normal file
24
test/lcm/lcm.py
Normal file
@ -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)
|
||||
6
test/lcm/lcm.test.py
Normal file
6
test/lcm/lcm.test.py
Normal file
@ -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)
|
||||
8
test/max_n/max_n.py
Normal file
8
test/max_n/max_n.py
Normal file
@ -0,0 +1,8 @@
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
def max_n(arr, n=1):
|
||||
numbers = deepcopy(arr)
|
||||
numbers.sort()
|
||||
numbers.reverse()
|
||||
return numbers[:n]
|
||||
6
test/max_n/max_n.test.py
Normal file
6
test/max_n/max_n.test.py
Normal file
@ -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)
|
||||
7
test/min_n/min_n.py
Normal file
7
test/min_n/min_n.py
Normal file
@ -0,0 +1,7 @@
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
def min_n(arr, n=1):
|
||||
numbers = deepcopy(arr)
|
||||
numbers.sort()
|
||||
return numbers[:n]
|
||||
6
test/min_n/min_n.test.py
Normal file
6
test/min_n/min_n.test.py
Normal file
@ -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)
|
||||
4
test/palindrome/palindrome.py
Normal file
4
test/palindrome/palindrome.py
Normal file
@ -0,0 +1,4 @@
|
||||
def palindrome(string):
|
||||
from re import sub
|
||||
s = sub('[\W_]', '', string.lower())
|
||||
return s == s[::-1]
|
||||
6
test/palindrome/palindrome.test.py
Normal file
6
test/palindrome/palindrome.test.py
Normal file
@ -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)
|
||||
12
test/shuffle/shuffle.py
Normal file
12
test/shuffle/shuffle.py
Normal file
@ -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
|
||||
6
test/shuffle/shuffle.test.py
Normal file
6
test/shuffle/shuffle.test.py
Normal file
@ -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)
|
||||
8
test/spread/spread.py
Normal file
8
test/spread/spread.py
Normal file
@ -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
|
||||
6
test/spread/spread.test.py
Normal file
6
test/spread/spread.test.py
Normal file
@ -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)
|
||||
8
test/zip/zip.py
Normal file
8
test/zip/zip.py
Normal file
@ -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
|
||||
6
test/zip/zip.test.py
Normal file
6
test/zip/zip.test.py
Normal file
@ -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)
|
||||
Reference in New Issue
Block a user