cours: quelques corrections

This commit is contained in:
Raito Bezarius 2020-06-17 18:52:07 +02:00
parent f157d9c4fb
commit 71e96b507a
2 changed files with 9 additions and 3 deletions

View file

@ -1,16 +1,21 @@
from hypothesis import given
from hypothesis.strategies import text
# Run-length encoder
# aaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbb ccccccccccccc ddddddddddddddd eeeeeeeeeeee
# 19a 18b …
def encode(input_string):
count = 1
prev = ''
lst = []
if not input_string:
return ([], 0)
for character in input_string:
if character != prev:
if prev:
entry = (prev,count)
lst.append(entry)
#print lst
count = 1
prev = character
else:
@ -32,4 +37,5 @@ def decode(lst):
@given(text())
def test_decode_inverts_encode(s):
assert decode(encode(s)) == s
lst, err = encode(s)
assert decode(lst) == s