Skip to content

Commit

Permalink
Merge pull request #14 from NioGreek/patch-0x00
Browse files Browse the repository at this point in the history
implemeted fill()
  • Loading branch information
John Anchery committed Jul 24, 2021
2 parents 3da3ac5 + ffa88f8 commit 6ecd931
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions clashgap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ._clash import Clash
from ._gap import gap
from ._fill import fill

__version__ = '0.2.0'

8 changes: 6 additions & 2 deletions clashgap/_clash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ._gap import gap
from ._fill import fill

class Clash:
def __init__(self, clash):
Expand All @@ -7,8 +8,11 @@ def __init__(self, clash):
def gap(self):
return self._gap

def __repr__(self):
return str(self._gap)
def fill(self):
return fill(self._gap)

def __str__(self):
return str(self._gap)

def __repr__(self):
return str(self._gap)
11 changes: 11 additions & 0 deletions clashgap/_fill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def fill(gap):
res = ["", ""]
for g in gap:
if isinstance(g, str):
res[0] += g
res[1] += g
else: #type(g) is list
res[0] += g[0]
res[1] += g[1]

return res
8 changes: 4 additions & 4 deletions clashgap/_gap.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This file contains the gap implementation and all the functions required for it

def list_has(arr, index):
def _list_has(arr, index):
return (len(arr) > index)

def collision(arr, brr):
def _collision(arr, brr):
for i, _ in enumerate(arr):
collision = brr.find(arr[i])
if collision != -1:
Expand All @@ -15,10 +15,10 @@ def gap(clash):
buff = ['', '']
for i, _ in enumerate(clash[0]):
buff[0] += clash[0][i]
if list_has(clash[1], i):
if _list_has(clash[1], i):
buff[1] += clash[1][i]

o, l = collision(buff[0], buff[1])
o, l = _collision(buff[0], buff[1])

if o != -1:
if buff[0][:o] or buff[1][:l]:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_clash.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
def test_gap():
assert clash.gap() == [['sp', 'h'], 'am']

def test_str():
assert str(clash) == "[['sp', 'h'], 'am']"

def test_repr():
assert repr(clash) == "[['sp', 'h'], 'am']"

def test_str():
assert str(clash) == "[['sp', 'h'], 'am']"
def test_fill():
assert clash.fill() == ["spam", "ham"]
5 changes: 5 additions & 0 deletions tests/test_fill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import clashgap as cg

def test_fill():
assert cg.fill([["sp", "h"], "am"]) == ["spam", "ham"]

7 changes: 4 additions & 3 deletions tests/test_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

def test_list_has():
arr = [1, 2]
assert cg._gap.list_has(arr, 1) == True
assert cg._gap.list_has(arr, 2) == False
assert cg._gap._list_has(arr, 0) == True
assert cg._gap._list_has(arr, 1) == True
assert cg._gap._list_has(arr, 2) == False

def test_collision():
assert cg._gap.collision("spam", "ham") == (2, 1)
assert cg._gap._collision("spam", "ham") == (2, 1)

def test_gap():
assert cg.gap(["spam", "ham"]) == [['sp', 'h'], 'am']
Expand Down

0 comments on commit 6ecd931

Please sign in to comment.