Els exemples que compten per la nota són només els que van seguits de ``# doctesttag: +TAG=...`` >>> from itertools import * Tests exercici 1 ---------------- >>> from zombie import moviments_zombie >>> lc1 = [(0, 0), (0, 100), (30, 100), (20, 100), (20, 85), (10, 85)] >>> lc2 = [(-x,-y) for x,y in lc1] >>> lc3 = [(0, 0), (0, 10), (0, 15), (0, 20), (-20, 20), (-20, 50), (20, 50), (20, 0), (-40, 0), (-40, -70), (40, -70), (-50, -70), (-50, -170), (-50, -60), (70, -60), (-60, -60), (80, -60), (80, -210), (80, -50), (-90, -50)] >>> lc4 = [(0, 0), (0, 20), (10, 20), (10, 0)] >>> lc5 = [(-x, -y) for x,y in lc3] >>> lc6 = [(0,0), (1,0), (0,0), (-1,0), (0,0), (0,1), (0,0), (0,-1)] >>> lc7 = [(-2*x, 3*y) for x,y in lc6] >>> lc8 = [(0,0), (0,10), (0,20), (0,10), (0,0), (10,0), (20,0), (10,0)] >>> for elem in moviments_zombie(iter(lc1[3:5])): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('S', 15), >>> for elem in moviments_zombie(iter(lc1)): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('N', 100),('E', 30),('O', 10),('S', 15),('O', 10), >>> for elem in moviments_zombie(iter(lc1[:-1] + lc1[::-1])): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('N', 100),('E', 30),('O', 10),('S', 15),('O', 10),('E', 10),('N', 15),('E', 10),('O', 30),('S', 100), >>> for elem in moviments_zombie(iter(lc2)): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('S', 100),('O', 30),('E', 10),('N', 15),('E', 10), >>> for elem in moviments_zombie(iter(lc3)): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('N', 10),('N', 5),('N', 5),('O', 20),('N', 30),('E', 40),('S', 50),('O', 60),('S', 70),('E', 80),('O', 90),('S', 100),('N', 110),('E', 120),('O', 130),('E', 140),('S', 150),('N', 160),('O', 170), >>> for elem in islice(moviments_zombie(cycle(lc4)), 1000, 1010): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('N', 20),('E', 10),('S', 20),('O', 10),('N', 20),('E', 10),('S', 20),('O', 10),('N', 20),('E', 10), >>> for elem in islice(moviments_zombie(cycle(lc6)), 10000, 10020): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('E', 1),('O', 1),('O', 1),('E', 1),('N', 1),('S', 1),('S', 1),('N', 1),('E', 1),('O', 1),('O', 1),('E', 1),('N', 1),('S', 1),('S', 1),('N', 1),('E', 1),('O', 1),('O', 1),('E', 1), >>> for elem in islice(moviments_zombie(cycle(lc7)), 100000, 100020): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('O', 2),('E', 2),('E', 2),('O', 2),('N', 3),('S', 3),('S', 3),('N', 3),('O', 2),('E', 2),('E', 2),('O', 2),('N', 3),('S', 3),('S', 3),('N', 3),('O', 2),('E', 2),('E', 2),('O', 2), >>> for elem in moviments_zombie(iter(lc8 * 2)): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('N', 10),('N', 10),('S', 10),('S', 10),('E', 10),('E', 10),('O', 10),('O', 10),('N', 10),('N', 10),('S', 10),('S', 10),('E', 10),('E', 10),('O', 10), >>> for elem in islice(moviments_zombie(cycle(lc8)), 1000000, 1000020): # doctesttag: +TAG=1_zombie ... print(elem, end=',') ('N', 10),('N', 10),('S', 10),('S', 10),('E', 10),('E', 10),('O', 10),('O', 10),('N', 10),('N', 10),('S', 10),('S', 10),('E', 10),('E', 10),('O', 10),('O', 10),('N', 10),('N', 10),('S', 10),('S', 10), Tests exercici 2 ---------------- >>> from extraccio import extreu_negatius >>> s1 = 'coordenades -10 23 -40 67 i 12 -50'.split() >>> s2 = 'uns quants símbols i sigles R2D2 KH7 N-245 i H2O2 4t 1a -hola- i dos negatius -789 -666'.split() >>> s3 = ( str(i*(-1)**i) for i in range(20) ) >>> s4 = '34534522 A18 18A A19B -X23 -34A -11 --45 +67 -67- 67- - +'.split() >>> s5 = '-1234567890 10-02-2025 -987654321 R12121212'.split() >>> for r in extreu_negatius(iter(s1)): # doctesttag: +TAG=2_negatius ... print(r, end=',') -10,-40,-50, >>> for r in extreu_negatius(iter(s2)): # doctesttag: +TAG=2_negatius ... print(r, end=',') -789,-666, >>> for r in extreu_negatius(iter(s1[::-1]+s2[::-1])): # doctesttag: +TAG=2_negatius ... print(r, end=',') -50,-40,-10,-666,-789, >>> for r in extreu_negatius(iter(s3)): # doctesttag: +TAG=2_negatius ... print(r, end=',') -1,-3,-5,-7,-9,-11,-13,-15,-17,-19, >>> for r in extreu_negatius(iter(s4)): # doctesttag: +TAG=2_negatius ... print(r, end=',') -11, >>> for r in extreu_negatius(s5): # doctesttag: +TAG=2_negatius ... print(r, end=',') -1234567890,-987654321, >>> for r in islice(extreu_negatius(repeat('-34')), 1000,1010): # doctesttag: +TAG=2_negatius ... print(r, end=',') -34,-34,-34,-34,-34,-34,-34,-34,-34,-34, >>> for r in islice(extreu_negatius(cycle(s1+s2+s5)), 10000, 10020): # doctesttag: +TAG=2_negatius ... print(r, end=',') -666,-1234567890,-987654321,-10,-40,-50,-789,-666,-1234567890,-987654321,-10,-40,-50,-789,-666,-1234567890,-987654321,-10,-40,-50, >>> for r in islice(extreu_negatius(cycle(s2+s4+s5)), 100000, 100020): # doctesttag: +TAG=2_negatius ... print(r, end=',') -789,-666,-11,-1234567890,-987654321,-789,-666,-11,-1234567890,-987654321,-789,-666,-11,-1234567890,-987654321,-789,-666,-11,-1234567890,-987654321, >>> for r in islice(extreu_negatius(cycle(['-45']*10 +['123']*100)), 1000000, 1000030): # doctesttag: +TAG=2_negatius ... print(r, end=',') -45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,-45,