Solució de l’examen final¶
- Organització:
Secció ETSEIB, Departament de Ciències de la Computació, UPC
- Data:
12 de juny de 2025
- Copyright:
Reconeixement-CompartirIgual 4.0 No adaptada de Creative Commons
Jocs de proves
tests.txt. Aquests jocs de proves fan servir el fitxersamarretes-nt.csv.
Els exemples que compten per la nota són només els que van seguits de
# doctesttag: +TAG=...
>>> from itertools import *
>>> import networkx as nx
>>> from connecta import nova_connexio
>>> from longs import longituds_camins
>>> from creixents import divideix_creixents
>>> from anual import vendes_anuals
>>> from talles import vendes_per_talla
Tests exercici 1.1¶
>>> dd = {'biblioteca': {'escola': {'connexio': 'pasarel·la'}, 'cementiri':{'connexio':'cami'}},'cementiri': {'escola': {'connexio': 'carretera'}},'gimnas': {'escola': {'connexio': 'porta'}},'escorxador': {},'escola': {'ajuntament': {'connexio': 'carrer'}}, 'arxiu': {'ajuntament': {'connexio': 'escales'}, 'clavagueram': {'connexio': 'escales'}},'hospital': {'clavagueram': {'connexio': 'porta'}, 'ajuntament': {'connexio': 'cami'}},'parc': {'ajuntament': {'connexio': 'cami'}}}
>>> g = nx.Graph(dd)
>>> nova_connexio(g,'cementiri','escola','carrer')
>>> g['cementiri']['escola'] # doctesttag: +TAG=1_nova_connexio
{'connexio': 'carretera/carrer'}
>>> nova_connexio(g,'plaça','escola','carrer')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['ajuntament', 'arxiu', 'escales'], ['ajuntament', 'cami', 'hospital'], ['ajuntament', 'cami', 'parc'], ['ajuntament', 'carrer', 'escola'], ['arxiu', 'clavagueram', 'escales'], ['biblioteca', 'cami', 'cementiri'], ['biblioteca', 'escola', 'pasarel·la'], ['carrer', 'escola', 'plaça'], ['carretera/carrer', 'cementiri', 'escola'], ['clavagueram', 'hospital', 'porta'], ['escola', 'gimnas', 'porta']]
>>> nova_connexio(g,'biblioteca','estadi','carretera')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['ajuntament', 'arxiu', 'escales'], ['ajuntament', 'cami', 'hospital'], ['ajuntament', 'cami', 'parc'], ['ajuntament', 'carrer', 'escola'], ['arxiu', 'clavagueram', 'escales'], ['biblioteca', 'cami', 'cementiri'], ['biblioteca', 'carretera', 'estadi'], ['biblioteca', 'escola', 'pasarel·la'], ['carrer', 'escola', 'plaça'], ['carretera/carrer', 'cementiri', 'escola'], ['clavagueram', 'hospital', 'porta'], ['escola', 'gimnas', 'porta']]
>>> nova_connexio(g,'cementiri','escola','carrer')
>>> g['cementiri']['escola'] # doctesttag: +TAG=1_nova_connexio
{'connexio': 'carretera/carrer'}
>>> dd2 = {'sauna': {}, 'padel': {},'tenis':{}, 'recepcio': {'sauna': {'connexio': 'porta'}}}
>>> g = nx.Graph(dd2)
>>> nova_connexio(g,'padel','tenis','cami')
>>> nova_connexio(g,'padel','tenis','saltant')
>>> nova_connexio(g,'tenis','recepcio','nadant')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['cami/saltant', 'padel', 'tenis'], ['nadant', 'recepcio', 'tenis'], ['porta', 'recepcio', 'sauna']]
>>> nova_connexio(g,'tenis','recepcio','nadant')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['cami/saltant', 'padel', 'tenis'], ['nadant', 'recepcio', 'tenis'], ['porta', 'recepcio', 'sauna']]
>>> g = nx.Graph(dd | dd2)
>>> nova_connexio(g,'padel','escola','bus')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['ajuntament', 'arxiu', 'escales'], ['ajuntament', 'cami', 'hospital'], ['ajuntament', 'cami', 'parc'], ['ajuntament', 'carrer', 'escola'], ['arxiu', 'clavagueram', 'escales'], ['biblioteca', 'cami', 'cementiri'], ['biblioteca', 'escola', 'pasarel·la'], ['bus', 'escola', 'padel'], ['carretera', 'cementiri', 'escola'], ['clavagueram', 'hospital', 'porta'], ['escola', 'gimnas', 'porta'], ['porta', 'recepcio', 'sauna']]
>>> nova_connexio(g,'padel','escola','metro')
>>> nova_connexio(g,'padel','escola','tram')
>>> nova_connexio(g,'hospital','cementiri','cotxe-de-morts')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['ajuntament', 'arxiu', 'escales'], ['ajuntament', 'cami', 'hospital'], ['ajuntament', 'cami', 'parc'], ['ajuntament', 'carrer', 'escola'], ['arxiu', 'clavagueram', 'escales'], ['biblioteca', 'cami', 'cementiri'], ['biblioteca', 'escola', 'pasarel·la'], ['bus/metro/tram', 'escola', 'padel'], ['carretera', 'cementiri', 'escola'], ['cementiri', 'cotxe-de-morts', 'hospital'], ['clavagueram', 'hospital', 'porta'], ['escola', 'gimnas', 'porta'], ['porta', 'recepcio', 'sauna']]
>>> nova_connexio(g,'ajuntament','clavegueram','ascensor')
>>> nova_connexio(g,'clavegueram','ajuntament','porta-giratoria')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['ajuntament', 'arxiu', 'escales'], ['ajuntament', 'ascensor/porta-giratoria', 'clavegueram'], ['ajuntament', 'cami', 'hospital'], ['ajuntament', 'cami', 'parc'], ['ajuntament', 'carrer', 'escola'], ['arxiu', 'clavagueram', 'escales'], ['biblioteca', 'cami', 'cementiri'], ['biblioteca', 'escola', 'pasarel·la'], ['bus/metro/tram', 'escola', 'padel'], ['carretera', 'cementiri', 'escola'], ['cementiri', 'cotxe-de-morts', 'hospital'], ['clavagueram', 'hospital', 'porta'], ['escola', 'gimnas', 'porta'], ['porta', 'recepcio', 'sauna']]
>>> nova_connexio(g,'padel','escola','tram')
>>> sorted(map(sorted, map(lambda x: (x[0], x[1], x[2]['connexio']), g.edges(data=True)))) # doctesttag: +TAG=1_nova_connexio
[['ajuntament', 'arxiu', 'escales'], ['ajuntament', 'ascensor/porta-giratoria', 'clavegueram'], ['ajuntament', 'cami', 'hospital'], ['ajuntament', 'cami', 'parc'], ['ajuntament', 'carrer', 'escola'], ['arxiu', 'clavagueram', 'escales'], ['biblioteca', 'cami', 'cementiri'], ['biblioteca', 'escola', 'pasarel·la'], ['bus/metro/tram', 'escola', 'padel'], ['carretera', 'cementiri', 'escola'], ['cementiri', 'cotxe-de-morts', 'hospital'], ['clavagueram', 'hospital', 'porta'], ['escola', 'gimnas', 'porta'], ['porta', 'recepcio', 'sauna']]
Tests exercici 1.2¶
>>> dd = {'biblioteca': {'escola': {'connexio': 'pasarel·la'}, 'cementiri':{'connexio':'cami'}},'cementiri': {'escola': {'connexio': 'carretera'}},'gimnas': {'escola': {'connexio': 'porta'}},'escorxador': {},'escola': {'ajuntament': {'connexio': 'carrer'}}, 'arxiu': {'ajuntament': {'connexio': 'escales'}, 'clavagueram': {'connexio': 'escales'}},'hospital': {'clavagueram': {'connexio': 'porta'}, 'ajuntament': {'connexio': 'cami'}},'parc': {'ajuntament': {'connexio': 'cami'}}}
>>> g = nx.Graph(dd)
>>> dd3 = {'sauna': {}, 'padel': {'tenis':{'connexio': 'cami', 'connexio':'saltant'}},'tenis':{'recepcio': {'connexio':'nadant'}}, 'recepcio': {'sauna': {'connexio': 'porta'}}}
>>> longituds_camins(g, 'escorxador', 'cementiri') # doctesttag: +TAG=1_longituds_camins
set()
>>> longituds_camins(g, 'hospital', 'biblioteca') == {3, 4, 5, 6} # doctesttag: +TAG=1_longituds_camins
True
>>> longituds_camins(g, 'hospital', 'ajuntament') == {1, 3} # doctesttag: +TAG=1_longituds_camins
True
>>> longituds_camins(g, 'gimnas', 'clavagueram') == {4} # doctesttag: +TAG=1_longituds_camins
True
>>> longituds_camins(g, 'cementiri', 'escola') == {1, 2} # doctesttag: +TAG=1_longituds_camins
True
>>> g = nx.complete_graph(5)
>>> longituds_camins(g, 1, 2) == {1, 2, 3, 4} # doctesttag: +TAG=1_longituds_camins
True
>>> g = nx.binomial_tree(6)
>>> longituds_camins(g, 1, 2) # doctesttag: +TAG=1_longituds_camins
{2}
>>> longituds_camins(g, 1, 6) # doctesttag: +TAG=1_longituds_camins
{3}
>>> g = nx.circulant_graph(8, [1, 2])
>>> longituds_camins(g, 1, 5) == {2, 3, 4, 5, 6, 7} # doctesttag: +TAG=1_longituds_camins
True
>>> g = nx.circulant_graph(8, [1, 3])
>>> longituds_camins(g, 1, 2) == {1, 3, 5, 7} # doctesttag: +TAG=1_longituds_camins
True
Tests exercici 2¶
>>> divideix_creixents([-5,-4,-3,-2,-1,0,1,10,100,1000]) # doctesttag: +TAG=2_divideix_creixents
[[-5, -4, -3, -2, -1, 0, 1, 10, 100, 1000]]
>>> divideix_creixents([3,2,1,0,-1,-2,-10,-100]) # doctesttag: +TAG=2_divideix_creixents
[[3], [2], [1], [0], [-1], [-2], [-10], [-100]]
>>> divideix_creixents([10,10,10,10,10]) # doctesttag: +TAG=2_divideix_creixents
[[10], [10], [10], [10], [10]]
>>> l = [1,10,100,1000]
>>> l == divideix_creixents(l)[0] # doctesttag: +TAG=2_divideix_creixents
True
>>> l = [1,2,3,4,5,6,7,8,9]
>>> divideix_creixents(l+l[::-1]) # doctesttag: +TAG=2_divideix_creixents
[[1, 2, 3, 4, 5, 6, 7, 8, 9], [9], [8], [7], [6], [5], [4], [3], [2], [1]]
>>> divideix_creixents([18, 75, 51, 25, 68, 50, 71, 34, 67, 98, 49, 68, 66, 75, 84, 8, 89, 89, 53]) # doctesttag: +TAG=2_divideix_creixents
[[18, 75], [51], [25, 68], [50, 71], [34, 67, 98], [49, 68], [66, 75, 84], [8, 89], [89], [53]]
>>> divideix_creixents([68, 39, 41, 73, 42, 19, 37, 11, 37, 50, 37, 98, 28, 2, 79, 7, 51, 20, 55, 25, 56]) # doctesttag: +TAG=2_divideix_creixents
[[68], [39, 41, 73], [42], [19, 37], [11, 37, 50], [37, 98], [28], [2, 79], [7, 51], [20, 55], [25, 56]]
>>> divideix_creixents([78, 51, 50, 81, 1, 16]) # doctesttag: +TAG=2_divideix_creixents
[[78], [51], [50, 81], [1, 16]]
>>> divideix_creixents([87, 64, 16, 70, 37, 32, 35, 11, 81]) # doctesttag: +TAG=2_divideix_creixents
[[87], [64], [16, 70], [37], [32, 35], [11, 81]]
>>> divideix_creixents([30, 82, 6, 98, 73, 54, 35, 51, 35, 36, 49, 37]) # doctesttag: +TAG=2_divideix_creixents
[[30, 82], [6, 98], [73], [54], [35, 51], [35, 36, 49], [37]]
>>> divideix_creixents([72, 25, 38, 55, 13, 47, 1, 12, 1, 93, 29, 39, 23, 70, 24, 31, 11, 85, 52]) # doctesttag: +TAG=2_divideix_creixents
[[72], [25, 38, 55], [13, 47], [1, 12], [1, 93], [29, 39], [23, 70], [24, 31], [11, 85], [52]]
>>> divideix_creixents([48, 41, 30, 20, 73, 14, 41, 81, 97, 15, 60, 77, 49, 70, 55, 33, 25, 12]) # doctesttag: +TAG=2_divideix_creixents
[[48], [41], [30], [20, 73], [14, 41, 81, 97], [15, 60, 77], [49, 70], [55], [33], [25], [12]]
>>> divideix_creixents([17, 87, 89, 77, 29, 32, 62, 65, 6, 22, 34, 58, 84, 61, 58, 58, 42, 82]) # doctesttag: +TAG=2_divideix_creixents
[[17, 87, 89], [77], [29, 32, 62, 65], [6, 22, 34, 58, 84], [61], [58], [58], [42, 82]]
>>> divideix_creixents([32, 0, 58, 18, 11, 28, 4, 0, 12, 43, 30, 72, 75, 31, 87, 66, 58, 68, 56, 91, 40]) # doctesttag: +TAG=2_divideix_creixents
[[32], [0, 58], [18], [11, 28], [4], [0, 12, 43], [30, 72, 75], [31, 87], [66], [58, 68], [56, 91], [40]]
>>> divideix_creixents([51, 16, 24, 13, 74, 46, 94, 64, 18, 35, 80, 72, 31, 65, 91, 90, 18, 41, 92]) # doctesttag: +TAG=2_divideix_creixents
[[51], [16, 24], [13, 74], [46, 94], [64], [18, 35, 80], [72], [31, 65, 91], [90], [18, 41, 92]]
>>> divideix_creixents([74, 88, 64, -86, 38, -66, 54, -9, 33, -31, -14, 45, -14, -5, 25, 35, -35]) # doctesttag: +TAG=2_divideix_creixents
[[74, 88], [64], [-86, 38], [-66, 54], [-9, 33], [-31, -14, 45], [-14, -5, 25, 35], [-35]]
>>> divideix_creixents([71, 35, -45, 61, -3, -68, 58, 71, -60, -5]) # doctesttag: +TAG=2_divideix_creixents
[[71], [35], [-45, 61], [-3], [-68, 58, 71], [-60, -5]]
>>> divideix_creixents([16, -76, 75, 59, -30, 18, 24]) # doctesttag: +TAG=2_divideix_creixents
[[16], [-76, 75], [59], [-30, 18, 24]]
>>> divideix_creixents([2, -20, -89, -97]) # doctesttag: +TAG=2_divideix_creixents
[[2], [-20], [-89], [-97]]
>>> divideix_creixents([72, 99, -15]) # doctesttag: +TAG=2_divideix_creixents
[[72, 99], [-15]]
>>> divideix_creixents([85, -44, 13, 37, 34, -25, -54, -25, 99, 46, -92, -72, -57, -87, -36, 81, -73, 57, 0, -53, -84, 74, -78, 17, -5, 67, -49, 21, 89, 60, -25, -1, 9, 30, 75, 6, 41, 26, -31, -16, -22, 49, -64, -21, 63, -15, 66, -23, -98, 52, -29, 11, -82, 23, -51, 91, -28, -62, -17, -20, 52, 75, -9, 4, 55, -37, 22, 62, -3, 59, -97, -39, -48, 19, 15, -43, -2, -44, -24, -67, 42, -80, 11, 42, -97, -16, 82, 47, 3, 7, 77, 43, 51, 17, 92, 60, -17, -5, 97, -80, -46, 45, 15, -34, -98, -81, -51, -52, -8, -21, -25, -26, 93, 27, 83, 57, -97, -86, -57, -74, 87, 20, -57, 27, -60, -27, 17, 24, 57, 13, 96, 30, 3, -45, -42, -50]) # doctesttag: +TAG=2_divideix_creixents
[[85], [-44, 13, 37], [34], [-25], [-54, -25, 99], [46], [-92, -72, -57], [-87, -36, 81], [-73, 57], [0], [-53], [-84, 74], [-78, 17], [-5, 67], [-49, 21, 89], [60], [-25, -1, 9, 30, 75], [6, 41], [26], [-31, -16], [-22, 49], [-64, -21, 63], [-15, 66], [-23], [-98, 52], [-29, 11], [-82, 23], [-51, 91], [-28], [-62, -17], [-20, 52, 75], [-9, 4, 55], [-37, 22, 62], [-3, 59], [-97, -39], [-48, 19], [15], [-43, -2], [-44, -24], [-67, 42], [-80, 11, 42], [-97, -16, 82], [47], [3, 7, 77], [43, 51], [17, 92], [60], [-17, -5, 97], [-80, -46, 45], [15], [-34], [-98, -81, -51], [-52, -8], [-21], [-25], [-26, 93], [27, 83], [57], [-97, -86, -57], [-74, 87], [20], [-57, 27], [-60, -27, 17, 24, 57], [13, 96], [30], [3], [-45, -42], [-50]]
>>> divideix_creixents([8, 32, -1, 27, 97, 46, 57, 98, -52, 97, 80, 36, 98, 39, 37, 1, 58, -5, -87, -6, 63, -36, 63, 62, -31, -29, -16, -39, -31, -68, 33, 98, 52, 13, 97, 50, 72, 49, 47, 18, -61, 35, 66, -75, 27, -63, -67, 46, -68, 66, -52, 17, 54, -69, 59, 41, -69, 33, -69, 45, 8, -52, -40, 29, 9, -9, -63, 88, 86, -68, -64, 60, -66, 2, -46, -8, -58, 77, 46, 94, -63, -30, 45, 46, 72, -47, 16, -85, -94, -10, -53, 88, -63, 93, 45, -64, 81, 72, -83, -1, 10, 13, -56, -36, -47, 26, -68, 40, 87, 75, 77, 28, -89, 5, -89, -31, 71, -24, 76, -5, -85, -15, -98, -19, 30, 46, 2, 47, -58, 25, 86, 82, -72, -8, 47, -24]) # doctesttag: +TAG=2_divideix_creixents
[[8, 32], [-1, 27, 97], [46, 57, 98], [-52, 97], [80], [36, 98], [39], [37], [1, 58], [-5], [-87, -6, 63], [-36, 63], [62], [-31, -29, -16], [-39, -31], [-68, 33, 98], [52], [13, 97], [50, 72], [49], [47], [18], [-61, 35, 66], [-75, 27], [-63], [-67, 46], [-68, 66], [-52, 17, 54], [-69, 59], [41], [-69, 33], [-69, 45], [8], [-52, -40, 29], [9], [-9], [-63, 88], [86], [-68, -64, 60], [-66, 2], [-46, -8], [-58, 77], [46, 94], [-63, -30, 45, 46, 72], [-47, 16], [-85], [-94, -10], [-53, 88], [-63, 93], [45], [-64, 81], [72], [-83, -1, 10, 13], [-56, -36], [-47, 26], [-68, 40, 87], [75, 77], [28], [-89, 5], [-89, -31, 71], [-24, 76], [-5], [-85, -15], [-98, -19, 30, 46], [2, 47], [-58, 25, 86], [82], [-72, -8, 47], [-24]]
>>> divideix_creixents([-65, 62, -68, 64, -43, -99, -60, 15, 22, -7, 10, 7, -43, -62, 42, 52, 96, 65, -31, -64, 79, -4, 31, -31, -98, -44, -80, 26, -41, -40, 71, 19, 8, -34, -30, 72, -24, 77, 56, 94, -29, -96, -47, -45, -15, 90, 99, 56, 58, 25, 61, 22, 56, 29, -5, 53, -36, 35, 61, -45, -59, -95, 17, 74, 68, 60, 98, -47, 27, -54, 99, 40, 84, 59, 12, 65, -96, 3, 40, 92, 80, 66, -44, -7, 27, 22, 32, -91, 16, 98, 32, -95, -46, -62, 98, -34, 53, 33, 23, -27, -89, 50]) # doctesttag: +TAG=2_divideix_creixents
[[-65, 62], [-68, 64], [-43], [-99, -60, 15, 22], [-7, 10], [7], [-43], [-62, 42, 52, 96], [65], [-31], [-64, 79], [-4, 31], [-31], [-98, -44], [-80, 26], [-41, -40, 71], [19], [8], [-34, -30, 72], [-24, 77], [56, 94], [-29], [-96, -47, -45, -15, 90, 99], [56, 58], [25, 61], [22, 56], [29], [-5, 53], [-36, 35, 61], [-45], [-59], [-95, 17, 74], [68], [60, 98], [-47, 27], [-54, 99], [40, 84], [59], [12, 65], [-96, 3, 40, 92], [80], [66], [-44, -7, 27], [22, 32], [-91, 16, 98], [32], [-95, -46], [-62, 98], [-34, 53], [33], [23], [-27], [-89, 50]]
>>> divideix_creixents([29, 3, -34, -83, 98, 77, 88, 93, 34, -63, 27, 32, -90, 58, -95, -84, 8, 19, 23, -94, -65, 59, 24, -9, 34, -72, -22, -73, -68, -59, -66, -94, -42, 82, -84, -46, -37, 21, -84, 53, -12, -44, -48, 80, 32, -28, 14, -26, -17, -17, 32, -47, -87, -9, 53, 61, 63, -70, -52, -25, -94, -23, -95, -82, 20, 59, -78, 70, -73, 89, 5, -53, 19, 37, -47, 61, 19, 88, -56, -23, -51, 58, 74, -33, -67, 50, -28, -53, -41, -97, -38, -38, 8, 84, 86, 57, 55, -17, 28, -36, 74, 48, -89, 24, -82, -9, 97, -31, -99, -82, 92, -62, 51, 21, -36, 14, 30, 67, -83, -66, -70, -97, -72, 53, 50]) # doctesttag: +TAG=2_divideix_creixents
[[29], [3], [-34], [-83, 98], [77, 88, 93], [34], [-63, 27, 32], [-90, 58], [-95, -84, 8, 19, 23], [-94, -65, 59], [24], [-9, 34], [-72, -22], [-73, -68, -59], [-66], [-94, -42, 82], [-84, -46, -37, 21], [-84, 53], [-12], [-44], [-48, 80], [32], [-28, 14], [-26, -17], [-17, 32], [-47], [-87, -9, 53, 61, 63], [-70, -52, -25], [-94, -23], [-95, -82, 20, 59], [-78, 70], [-73, 89], [5], [-53, 19, 37], [-47, 61], [19, 88], [-56, -23], [-51, 58, 74], [-33], [-67, 50], [-28], [-53, -41], [-97, -38], [-38, 8, 84, 86], [57], [55], [-17, 28], [-36, 74], [48], [-89, 24], [-82, -9, 97], [-31], [-99, -82, 92], [-62, 51], [21], [-36, 14, 30, 67], [-83, -66], [-70], [-97, -72, 53], [50]]
>>> divideix_creixents([-5, -52, 71, -80, 29, 85, 76, -84, 33, -89, -24, -63, 90, 74, -88, -42, 28, 50, 98, -82, 94, -15, 15, -89, 28, -89, 31, -41, 30, -56, -22, 27, -41, -89, -90, 23, 70, -43, 47, 58, 58, -47, -68, 35, -24, -78, 51, -5, 80, -66, -27, 68, 1, 97, -80, 41, -32, -54, 20, 76, -22, 62, -96, 40, 40, 94, 45, -86, 80, 57, -25, 79, -75, -19, -53, -20, 30, -44, 16, -37, 0, -83, 33, -18, 56, 55, -40, 57, 59, -44, 89, -98, -32, -37, -80, -43, 32, -42, -17, -65, -72, 61, -39, -75, -36, 61, 4, -72, 12, 77, -51, 22, -70, -62, 68, -42, -31, 29, -32, -5, -46, -88, -2, -5, -45, -38, 49, 26, 54, -47, 1, 35, -15, 25, 80, 90, 64, 49, 52, 38, -31, 67, -28, -8, 19, 63]) # doctesttag: +TAG=2_divideix_creixents
[[-5], [-52, 71], [-80, 29, 85], [76], [-84, 33], [-89, -24], [-63, 90], [74], [-88, -42, 28, 50, 98], [-82, 94], [-15, 15], [-89, 28], [-89, 31], [-41, 30], [-56, -22, 27], [-41], [-89], [-90, 23, 70], [-43, 47, 58], [58], [-47], [-68, 35], [-24], [-78, 51], [-5, 80], [-66, -27, 68], [1, 97], [-80, 41], [-32], [-54, 20, 76], [-22, 62], [-96, 40], [40, 94], [45], [-86, 80], [57], [-25, 79], [-75, -19], [-53, -20, 30], [-44, 16], [-37, 0], [-83, 33], [-18, 56], [55], [-40, 57, 59], [-44, 89], [-98, -32], [-37], [-80, -43, 32], [-42, -17], [-65], [-72, 61], [-39], [-75, -36, 61], [4], [-72, 12, 77], [-51, 22], [-70, -62, 68], [-42, -31, 29], [-32, -5], [-46], [-88, -2], [-5], [-45, -38, 49], [26, 54], [-47, 1, 35], [-15, 25, 80, 90], [64], [49, 52], [38], [-31, 67], [-28, -8, 19, 63]]
Tests exercici 3.1¶
>>> import pandas as pd
>>> df = pd.read_csv('samarretes-nt.csv', parse_dates=['Data'])
>>> nv, imp = vendes_anuals(df, 2000)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:1313. Import vendes:26156.50'
>>> nv, imp = vendes_anuals(df, 2007)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:1034. Import vendes:20907.10'
>>> nv, imp = vendes_anuals(df, 2001)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:1342. Import vendes:28098.70'
>>> nv, imp = vendes_anuals(df, 2025)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:0. Import vendes:0.00'
>>> nv, imp = vendes_anuals(df, 2002)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:1325. Import vendes:23760.70'
>>> nv, imp = vendes_anuals(df.iloc[:100], 2004)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:0. Import vendes:0.00'
>>> nv, imp = vendes_anuals(df.iloc[:300], 2004)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:1126. Import vendes:22214.60'
>>> nv, imp = vendes_anuals(df, 2050)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:0. Import vendes:0.00'
>>> nv, imp = vendes_anuals(df.iloc[300:], 2004)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:431. Import vendes:9889.80'
>>> nv, imp = vendes_anuals(df.iloc[:300], 2002)
>>> f"Samarretes venudes:{nv}. Import vendes:{imp:.2f}" # doctesttag: +TAG=3_vendes_anuals
'Samarretes venudes:1325. Import vendes:23760.70'
Tests exercici 3.2¶
>>> d = vendes_per_talla(df, '*')
>>> if d != {'L': 3040, 'M': 4017, 'S': 3305, 'XL': 3208, 'XS': 3331, 'XXL': 3521}: # doctesttag: +TAG=3_vendes_per_talla
... print(f"El valor retornat no és l'esperat: {d}")
>>> d = vendes_per_talla(df.iloc[100:800], 'home')
>>> if d != {'L': 995, 'M': 1094, 'S': 1148, 'XL': 1126, 'XS': 1271, 'XXL': 1285}: # doctesttag: +TAG=3_vendes_per_talla
... print(f"El valor retornat no és l'esperat: {d}")
>>> d = vendes_per_talla(df.iloc[100:200], 'dona')
>>> if d != {'L': 104, 'M': 318, 'S': 85, 'XL': 87, 'XS': 118, 'XXL': 170}: # doctesttag: +TAG=3_vendes_per_talla
... print(f"El valor retornat no és l'esperat: {d}")
>>> d = vendes_per_talla(df, 'dona')
>>> if d != {'L': 1653, 'M': 2304, 'S': 1754, 'XL': 1571, 'XS': 1748, 'XXL': 1677}: # doctesttag: +TAG=3_vendes_per_talla
... print(f"El valor retornat no és l'esperat: {d}")
>>> d = vendes_per_talla(df, 'home')
>>> if d != {'L': 1387, 'M': 1713, 'S': 1551, 'XL': 1637, 'XS': 1583, 'XXL': 1844}: # doctesttag: +TAG=3_vendes_per_talla
... print(f"El valor retornat no és l'esperat: {d}")
>>> d = vendes_per_talla(df.iloc[100:101], 'home')
>>> if d != {'XXL': 34}: # doctesttag: +TAG=3_vendes_per_talla
... print(f"El valor retornat no és l'esperat: {d}")
>>> d = vendes_per_talla(df.iloc[200:220], 'dona')
>>> if d != {'L': 47, 'M': 147, 'S': 88, 'XL': 41, 'XXL': 78}: # doctesttag: +TAG=3_vendes_per_talla
... print(f"El valor retornat no és l'esperat: {d}")
>>> vendes_per_talla(df.iloc[200:220], '*') == {'L': 81, 'M': 162, 'S': 88, 'XL': 41, 'XS': 12, 'XXL': 125} # doctesttag: +TAG=3_vendes_per_talla
True
>>> vendes_per_talla(df.iloc[:100], '*') == {'L': 286, 'M': 527, 'S': 252, 'XL': 419, 'XS': 236, 'XXL': 361} # doctesttag: +TAG=3_vendes_per_talla
True
>>> vendes_per_talla(df.iloc[10:12], '*') # doctesttag: +TAG=3_vendes_per_talla
{'L': 34}