def test_get_num_infected(): graph = CoachingGraph() A = User() B = User() C = User() graph.add_users([A, B, C]) A.infected = True B.infected = True infecter = Infecter() assert infecter.get_num_infected(graph.users) == 2
def test_find_user_with_fewest_connections(): subgraph = CoachingGraph() A = User() B = User() C = User() D = User() subgraph.add_users([A, B, D, C]) subgraph.create_coach_coachee_relationship(A, B) subgraph.create_coach_coachee_relationship(A, C) subgraph.create_coach_coachee_relationship(A, D) subgraph.create_coach_coachee_relationship(B, C) expected = D infecter = Infecter() actual = infecter.find_user_with_fewest_connections(subgraph.users) assert expected == actual
def resource_user_and_subgraph_list(): graph = CoachingGraph() A = User() B = User() C = User() D = User() E = User() F = User() coachee1 = User() coachee2 = User() coachee3 = User() coachee4 = User() G = User() H = User() I = User() J = User() K = User() graph.add_users([ A, B, C, D, E, F, coachee1, coachee2, coachee3, coachee4, G, H, I, J, K ]) graph.create_coach_coachee_relationship(A, B) graph.create_coach_coachee_relationship(B, C) graph.create_coach_coachee_relationship(C, A) graph.create_coach_coachee_relationship(C, D) graph.create_coach_coachee_relationship(D, E) subgraph1 = [A, B, C, D, E] graph.create_coach_coachee_relationship(F, coachee1) graph.create_coach_coachee_relationship(F, coachee2) graph.create_coach_coachee_relationship(F, coachee3) graph.create_coach_coachee_relationship(F, coachee4) subgraph2 = [F, coachee1, coachee2, coachee3, coachee4] graph.create_coach_coachee_relationship(G, H) graph.create_coach_coachee_relationship(H, I) graph.create_coach_coachee_relationship(I, G) graph.create_coach_coachee_relationship(J, G) graph.create_coach_coachee_relationship(J, I) graph.create_coach_coachee_relationship(K, G) graph.create_coach_coachee_relationship(K, H) subgraph3 = [G, H, I, J, K] return graph.users, [subgraph1, subgraph2, subgraph3]
def test_get_connected_network(): graph = CoachingGraph() A = User() B = User() C = User() D = User() E = User() F = User() graph.add_users([A, B, C, D, E, F]) graph.create_coach_coachee_relationship(A, B) graph.create_coach_coachee_relationship(B, C) graph.create_coach_coachee_relationship(C, A) graph.create_coach_coachee_relationship(C, D) graph.create_coach_coachee_relationship(D, E) network = graphTraverser.get_connected_network(A) assert set(network) == set([A, B, C, D, E])
def resource_user_and_subgraph_list(): graph = CoachingGraph() A = User() B = User() C = User() D = User() E = User() F = User() coachee1 = User() coachee2 = User() coachee3 = User() coachee4 = User() G = User() H = User() I = User() J = User() K = User() graph.add_users([A, B, C, D, E, F, coachee1, coachee2, coachee3, coachee4, G, H, I, J, K]) graph.create_coach_coachee_relationship(A, B) graph.create_coach_coachee_relationship(B, C) graph.create_coach_coachee_relationship(C, A) graph.create_coach_coachee_relationship(C, D) graph.create_coach_coachee_relationship(D, E) subgraph1 = [A, B, C, D, E] graph.create_coach_coachee_relationship(F, coachee1) graph.create_coach_coachee_relationship(F, coachee2) graph.create_coach_coachee_relationship(F, coachee3) graph.create_coach_coachee_relationship(F, coachee4) subgraph2 = [F, coachee1, coachee2, coachee3, coachee4] graph.create_coach_coachee_relationship(G, H) graph.create_coach_coachee_relationship(H, I) graph.create_coach_coachee_relationship(I, G) graph.create_coach_coachee_relationship(J, G) graph.create_coach_coachee_relationship(J, I) graph.create_coach_coachee_relationship(K, G) graph.create_coach_coachee_relationship(K, H) subgraph3 = [G, H, I, J, K] return graph.users, [subgraph1, subgraph2, subgraph3]
def test_get_subgraphs(): graph = CoachingGraph() A = User() B = User() C = User() D = User() E = User() F = User() graph.add_users([A, B, C, D, E, F]) graph.create_coach_coachee_relationship(A, B) graph.create_coach_coachee_relationship(C, D) graph.create_coach_coachee_relationship(D, E) subgraphs = graphTraverser.get_subgraphs(graph.users) subgraphs = set(tuple([frozenset(tuple(subgraph)) for subgraph in subgraphs])) assert frozenset(tuple([A, B])) in subgraphs assert frozenset(tuple([C, D, E])) in subgraphs assert frozenset(tuple([F])) in subgraphs
def test_get_connected_network(): graph = CoachingGraph() A = User() B = User() C = User() D = User() E = User() F = User() graph.add_users([A, B, C, D, E, F]) graph.create_coach_coachee_relationship(A, B) graph.create_coach_coachee_relationship(B, C) graph.create_coach_coachee_relationship(C, A) graph.create_coach_coachee_relationship(C, D) graph.create_coach_coachee_relationship(D, E) network = graphTraverser.get_connected_network(A) assert set(network) == set([A, B, C, D, E])
def test_get_subgraphs(): graph = CoachingGraph() A = User() B = User() C = User() D = User() E = User() F = User() graph.add_users([A, B, C, D, E, F]) graph.create_coach_coachee_relationship(A, B) graph.create_coach_coachee_relationship(C, D) graph.create_coach_coachee_relationship(D, E) subgraphs = graphTraverser.get_subgraphs(graph.users) subgraphs = set( tuple([frozenset(tuple(subgraph)) for subgraph in subgraphs])) assert frozenset(tuple([A, B])) in subgraphs assert frozenset(tuple([C, D, E])) in subgraphs assert frozenset(tuple([F])) in subgraphs
def test_find_neighbor_with_fewest_connections(): graph = CoachingGraph() A = User() B = User() C = User() D = User() E = User() F = User() graph.add_users([A, B, C, D, E, F]) graph.create_coach_coachee_relationship(A, B) graph.create_coach_coachee_relationship(B, C) graph.create_coach_coachee_relationship(B, D) graph.create_coach_coachee_relationship(C, E) graph.create_coach_coachee_relationship(A, F) infecter = Infecter() infecter.infect_single_user(A) userWithFewest = infecter.find_neighbor_with_fewest_connections(A) assert userWithFewest == F