Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ var/
.installed.cfg
*.egg
bin/
lib/
include/
.DS_Store
pyvenv.cfg

# PyInstaller
Expand Down
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Repo containing my solutions from Code War katas.
Repo containing my solutions from Code Katas.

###8kyu

Expand Down Expand Up @@ -140,4 +140,62 @@ def find_it(xs):
```
def countBits(n):
return bin(n).count("1")
```
```


###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 =====================
```
5 changes: 5 additions & 0 deletions sort_cards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Implementation of the Sort Cards Kata."""




21 changes: 21 additions & 0 deletions src/autocomplete.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions src/count_bits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
18 changes: 18 additions & 0 deletions src/tests/test_autocomplete.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions src/tests/test_parenthetics.py
Original file line number Diff line number Diff line change
@@ -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'
17 changes: 17 additions & 0 deletions src/tests/test_sort_cards.py
Original file line number Diff line number Diff line change
@@ -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