mirror of
				https://github.com/newtype256/esgi-devops.git
				synced 2025-11-04 04:00:47 +01:00 
			
		
		
		
	cours: quelques corrections
This commit is contained in:
		
							parent
							
								
									f157d9c4fb
								
							
						
					
					
						commit
						71e96b507a
					
				
					 2 changed files with 9 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue