>>> import networkx as nx >>> from glaber import * TESTS crea_graf_laberint >>> g1 = crea_graf_laberint(4, 2) >>> sorted(g1.nodes()) [(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (4, 1), (4, 2)] >>> sorted(map(sorted, g1.edges)) [[(1, 1), (1, 2)], [(1, 1), (2, 1)], [(1, 2), (2, 2)], [(2, 1), (2, 2)], [(2, 1), (3, 1)], [(2, 2), (3, 2)], [(3, 1), (3, 2)], [(3, 1), (4, 1)], [(3, 2), (4, 2)], [(4, 1), (4, 2)]] >>> g = crea_graf_laberint(3, 5) >>> list(g.nodes) [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5)] >>> len(g.edges()) 22 TESTS afegir_paret # continua amb el graf g del doctest anterior >>> afegir_paret(g, (1,1), (2,1)) >>> len(g.edges()) 21 >>> afegir_paret(g, (1,2), (2,2)) >>> afegir_paret(g, (2,3), (2,2)) >>> afegir_paret(g, (2,2), (3,2)) >>> afegir_paret(g, (2,4), (1,4)) >>> afegir_paret(g, (2,4), (3,4)) >>> afegir_paret(g, (2,5), (3,5)) # ara hauria de quedar el laberint com en l'exemple: >>> sorted(map(sorted,g.edges)) [[(1, 1), (1, 2)], [(1, 2), (1, 3)], [(1, 3), (1, 4)], [(1, 3), (2, 3)], [(1, 4), (1, 5)], [(1, 5), (2, 5)], [(2, 1), (2, 2)], [(2, 1), (3, 1)], [(2, 3), (2, 4)], [(2, 3), (3, 3)], [(2, 4), (2, 5)], [(3, 1), (3, 2)], [(3, 2), (3, 3)], [(3, 3), (3, 4)], [(3, 4), (3, 5)]] TESTS quants_camins >>> quants_camins(g, (1,1), (1,3)) 1 >>> quants_camins(g, (1,2), (2,5)) 2 >>> quants_camins(g, (1,1), (2,2)) 2 >>> g.add_edge((1,2), (2,2)) >>> quants_camins(g, (1,1), (2,2)) 3 >>> quants_camins(g, (1,5), (2,1)) 4 >>> g.remove_edge((1,2), (2,2)) TESTS afegir_teletransport >>> afegir_teletransport(g, (3,1), (2,5)) >>> g[(3,1)][(2,5)] {'tipus': 'teletransport'} >>> g[(1,1)][(1,2)] {} >>> afegir_teletransport(g, (2,2), (3,5)) >>> g[(2,2)][(3,5)] {'tipus': 'teletransport'} >>> afegir_teletransport(g, (2,3), (8,8)) >>> g[(2,3)][(8,8)] {'tipus': 'teletransport'} TESTS millor_cami >>> millor_cami(g, (1,1), (1,2)) 'NORMAL' >>> millor_cami(g, (2,2), (2,4)) 'TELETRANSPORT' >>> millor_cami(g, (1,1), (8,8)) 'TELETRANSPORT' >>> millor_cami(g, (1,1), (1,5)) 'NORMAL' >>> g.add_nodes_from([(1,6), (2,6), (2,7)]) >>> millor_cami(g, (1,1), (1,6)) 'IMPOSSIBLE' >>> millor_cami(g, (8,8), (2,6)) 'IMPOSSIBLE'