diff --git a/.gitignore b/.gitignore index 92cd3f7..235737e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,9 @@ var/ .installed.cfg *.egg bin/ +lib/ +include/ +.DS_Store pyvenv.cfg # PyInstaller diff --git a/README.md b/README.md index 82dbc43..6b98eeb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Repo containing my solutions from Code War katas. +Repo containing my solutions from Code Katas. ###8kyu @@ -140,4 +140,62 @@ def find_it(xs): ``` def countBits(n): return bin(n).count("1") -``` \ No newline at end of file +``` + + +###Other + + +####Interview Challenge: Proper Parenthetics +- Module: proper-parenthetics.py +- TESTS: test_proper-parenthetics.py +- LINKS: None. +- DERIVED FROM: [data-structures repo. Specifically stack branch](https://github.com/ellezv/data_structures/tree/stack), collaborated with Maelle Vance. + + +####Autocomplete +- Module: autocomplete.py +- TESTS: test_autocomplete.py +- LINKS: None. + + +###COVERAGE + +``` + +---------- coverage: platform darwin, python 3.5.2-final-0 ----------- +Name Stmts Miss Cover Missing +----------------------------------------------------------------- +src/autocomplete.py 13 0 100% +src/calculate_years.py 8 0 100% +src/count_bits.py 5 0 100% +src/decending_order.py 6 6 0% 4-10 +src/find_odd_int.py 4 0 100% +src/is_isogram.py 8 0 100% +src/multiply.py 2 0 100% +src/parenthetics.py 48 0 100% +src/remove_min.py 6 0 100% +src/shortest_word.py 7 0 100% +src/sort_cards.py 34 13 62% 11-12, 22, 28-32, 36-38, 51-52 +src/sum_terms.py 2 0 100% +src/tests/__init__.py 0 0 100% +src/tests/test_autocomplete.py 7 0 100% +src/tests/test_calculate_years.py 5 0 100% +src/tests/test_count_bits.py 5 0 100% +src/tests/test_decending_order.py 5 2 60% 16-17 +src/tests/test_find_odd_int.py 5 0 100% +src/tests/test_is_isogram.py 5 0 100% +src/tests/test_multiply.py 5 0 100% +src/tests/test_parenthetics.py 12 0 100% +src/tests/test_remove_min.py 5 0 100% +src/tests/test_shortest_word.py 5 0 100% +src/tests/test_sort_cards.py 7 0 100% +src/tests/test_sum_terms.py 5 0 100% +src/tests/test_xo.py 5 0 100% +src/xo.py 5 0 100% +----------------------------------------------------------------- +TOTAL 224 21 91% + + +===================== 45 passed in 0.38 seconds ===================== +``` diff --git a/sort_cards.py b/sort_cards.py new file mode 100644 index 0000000..1df1bee --- /dev/null +++ b/sort_cards.py @@ -0,0 +1,5 @@ +"""Implementation of the Sort Cards Kata.""" + + + + diff --git a/src/autocomplete.py b/src/autocomplete.py new file mode 100644 index 0000000..fa759dd --- /dev/null +++ b/src/autocomplete.py @@ -0,0 +1,21 @@ +"""Implementation of the autocomplete module.""" + + +class AutoCompleter(): + """Auto completer class.""" + + def __init__(self, vocabulary, max_completions=4): + """Instantiate with vocabulary and max_compete params.""" + self.vocabulary = vocabulary + self.max_completions = max_completions + + def complete(self, term): + """Match terms to max of 4 words, then append and return.""" + suggested_words = [] + n = len(term) + for word in self.vocabulary: + if word[:n] == term: + suggested_words.append(word) + if len(suggested_words) >= self.max_completions: + return suggested_words + return suggested_words diff --git a/src/count_bits.py b/src/count_bits.py index f131316..e49dcb9 100644 --- a/src/count_bits.py +++ b/src/count_bits.py @@ -3,7 +3,5 @@ def count_bits(n): """Convert a number to binary and counts the number of 1 bits.""" - print(n) val = bin(n) - print(val) return val.count("1") diff --git a/src/tests/test_autocomplete.py b/src/tests/test_autocomplete.py new file mode 100644 index 0000000..c554c2e --- /dev/null +++ b/src/tests/test_autocomplete.py @@ -0,0 +1,18 @@ +"""Tests for autocomplete module.""" +import pytest + +TEST_TABLE = [ + ['f', ['fix', 'fax', 'fit', 'fist']], + ['fi', ['fix', 'fit', 'fist', 'finch']], + ['fin', ['finch', 'final', 'finial']], + ['finally', []] +] + + +@pytest.mark.parametrize("n, result", TEST_TABLE) +def test_autocomplete(n, result): + """Test the series_sum function.""" + from autocomplete import AutoCompleter + vocabulary = ['fix', 'fax', 'fit', 'fist', 'full', 'finch', 'final', 'finial'] + complete_me = AutoCompleter(vocabulary, max_completions=4) + assert complete_me.complete(n) == result diff --git a/src/tests/test_parenthetics.py b/src/tests/test_parenthetics.py new file mode 100644 index 0000000..ae87c75 --- /dev/null +++ b/src/tests/test_parenthetics.py @@ -0,0 +1,28 @@ +"""Tests for parenthetics module.""" + + +import pytest + + +PAREN_TABLE = [ + ['((()))', 0], + ['((())', 1], + [')))(((', -1] +] + + +@pytest.mark.parametrize("uni_string, result", PAREN_TABLE) +def test_parenthetics(uni_string, result): + """Test the parenthetics function.""" + from parenthetics import parenthetics + assert parenthetics(uni_string) == result + + +def test_pop_empty(): + """Test the parenthetics function.""" + from parenthetics import LinkedList + list = LinkedList() + try: + list.pop() + except Exception as e: + assert str(e) == 'cannot pop from empty list' diff --git a/src/tests/test_sort_cards.py b/src/tests/test_sort_cards.py new file mode 100644 index 0000000..94d55c6 --- /dev/null +++ b/src/tests/test_sort_cards.py @@ -0,0 +1,17 @@ +"""Tests for sort_cards module.""" +import pytest + +SORT_TABLE = [ + ['39A5T824Q7J6K', 'A23456789TJQK'], + ['Q286JK395A47T', 'A23456789TJQK'], + ['54TQKJ69327A8', 'A23456789TJQK'] +] + + +@pytest.mark.parametrize("cards, result", SORT_TABLE) +def test_sort_cards(cards, result): + """Test the sort_cards function.""" + from sort_cards import sort_cards + result = sort_cards(list(cards)) + expected = list(result) + assert result == expected