def test_no_user_has_self_as_neighbor():
	graph = CoachingGraph()
	graph.init_semi_random(100)
	for user in graph.users:
		if user in user.neighbors:
			assert False
	assert True
Example #2
0
def test_add_user():
    graph = CoachingGraph()
    userA = User()

    graph.add_user(userA)

    assert userA in graph.users
Example #3
0
def test_no_user_has_self_as_neighbor():
    graph = CoachingGraph()
    graph.init_semi_random(100)
    for user in graph.users:
        if user in user.neighbors:
            assert False
    assert True
def test_add_user():
	graph = CoachingGraph()
	userA = User()

	graph.add_user(userA)

	assert userA in graph.users
def resource_add_coach():
	graph = CoachingGraph()

	graph.add_coach(20)
	
	coaches = [user for user in graph.users if len(user.coachees) > 0]
	coachees = [user for user in graph.users if len(user.coaches) > 0]
	return coaches, coachees
Example #6
0
def test_save_and_load():
    graph = CoachingGraph()
    graph.init_semi_random(100)
    graph.save_as('save_and_load')
    graphB = CoachingGraph()
    graphB.load_from('save_and_load')

    assert len(graph.users) == len(graphB.users)
Example #7
0
def resource_add_coach():
    graph = CoachingGraph()

    graph.add_coach(20)

    coaches = [user for user in graph.users if len(user.coachees) > 0]
    coachees = [user for user in graph.users if len(user.coaches) > 0]
    return coaches, coachees
def test_add_students():
	graph = CoachingGraph()
	A = User()
	graph.add_user(A)

	graph.add_coachees(A, 10)

	assert len(A.coachees) == 10
Example #9
0
def test_traverse_from_collect_if():
    graphA = CoachingGraph()
    graphA.init_semi_random_connected(100)

    actualA = len(graphA.users)
    network = graphTraverser.get_connected_network(graphA.users[0])
    sizeA = len(network)

    assert sizeA == actualA
Example #10
0
def test_get_subgraphs_connected():
    graph = CoachingGraph()
    graph.init_semi_random_connected(100)
    subgraphs = graphTraverser.get_subgraphs(graph.users)
    combined = []
    for subgraph in subgraphs:
        combined.extend(subgraph)

    assert set(combined) == set(graph.users)
def resource_create_coach_coachee_relationship():
	graph = CoachingGraph()
	A = User()
	B = User()
	graph.add_user(A)
	graph.add_user(B)

	graph.create_coach_coachee_relationship(A, B)
	return A,B
def test_make_sparse_random_connections():
	graph = CoachingGraph()
	graph.create_and_add_users(20)
	graph.make_sparse_random_connections(5)

	numConnections = 0
	for user in graph.users:
		numConnections += len(user.coaches)
	assert numConnections == 5
def test_get_subgraphs_connected():
	graph = CoachingGraph()
	graph.init_semi_random_connected(100)
	subgraphs = graphTraverser.get_subgraphs(graph.users)
	combined = []
	for subgraph in subgraphs:
		combined.extend(subgraph)

	assert set(combined) == set(graph.users)
def test_traverse_from_collect_if():
	graphA = CoachingGraph()
	graphA.init_semi_random_connected(100)

	actualA = len(graphA.users)
	network = graphTraverser.get_connected_network(graphA.users[0])
	sizeA = len(network)

	assert sizeA == actualA
Example #15
0
def test_get_num_infected_large():
	expectedInfected = 100
	graph = CoachingGraph()
	graph.init_semi_random(expectedInfected)
	infecter = Infecter()

	infecter.infect_all(graph.users)
	actualInfected = infecter.get_num_infected(graph.users)

	assert actualInfected == expectedInfected
Example #16
0
def test_infect_limited_doesnt_change_num_users():
	originalUsers = 100
	graph = CoachingGraph()
	graph.init_semi_random(originalUsers)
	infecter = Infecter()

	infecter.infect_limited(graph.users, 50, 10)
	remaingingUsers = len(graph.users)

	assert remaingingUsers == originalUsers
Example #17
0
def load_test_graphs(folderName):
	testGraphs = []

	dirName = get_test_data_directory(folderName)
	fileNames = get_files_from_directory_with_suffix(dirName, TEST_GRAPH_SUFFIX)
	for file in fileNames:
		fullPath = os.path.join(dirName, file)
		graph = CoachingGraph()
		graph.load_from(fullPath)
		testGraphs.append(graph)
	return testGraphs
Example #18
0
def test_infect_limited_infects_correct_number_connected():
	graph = CoachingGraph()
	graph.init_semi_random_connected(200)
	numToInfect = 70
	users = graph.users
	infecter = Infecter()

	infecter.infect_limited(users, numToInfect, 0, False)
	numInfected = infecter.get_num_infected(users)

	assert numInfected == numToInfect
Example #19
0
def test_infect_limited_from():
	graph = CoachingGraph()
	graph.init_semi_random_connected(200)
	numToInfect = 70
	users = graph.users
	user = random.choice(users)
	infecter = Infecter()

	infecter.infect_limited_from(user, numToInfect)
	numInfected = infecter.get_num_infected(users)

	assert numInfected == numToInfect
Example #20
0
def load_test_graphs(folderName):
    testGraphs = []

    dirName = get_test_data_directory(folderName)
    fileNames = get_files_from_directory_with_suffix(dirName,
                                                     TEST_GRAPH_SUFFIX)
    for file in fileNames:
        fullPath = os.path.join(dirName, file)
        graph = CoachingGraph()
        graph.load_from(fullPath)
        testGraphs.append(graph)
    return testGraphs
Example #21
0
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
Example #22
0
def generate_test_graphs_connected(dirName, numGraphs, maxSize):
	logger.info("generating test graphs in directory: {}".format(dirName))
	folderPath = refresh_testData_folder(dirName)

	for i in range(numGraphs):
		graph = CoachingGraph()

		fileNumber = i + 1
		fileName = '{}_'.format(fileNumber) + TEST_GRAPH_SUFFIX

		randomSize = random.randint(40, maxSize)
		graph.init_semi_random_connected(randomSize)

		filePath = os.path.join(folderPath, fileName)
		graph.save_as(filePath)
def test_save_and_load():
	graph = CoachingGraph()
	graph.init_semi_random(100)
	graph.save_as('save_and_load')
	graphB = CoachingGraph()
	graphB.load_from('save_and_load')

	assert len(graph.users) == len(graphB.users)
Example #24
0
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])
Example #25
0
def generate_test_graphs(dirName, numGraphs, maxSize):
	logger.info("generating test graphs in directory: {}".format(dirName))
	folderPath = refresh_testData_folder(dirName)
	graphs = []
	for i in range(numGraphs):
		graph = CoachingGraph()

		fileNumber = i + 1
		fileName = '{}_'.format(fileNumber) + TEST_GRAPH_SUFFIX

		randomSize = random.randint(100, maxSize)
		randomInternalConnections = random.randint(2, 12)
		randomCoacheesFactor = random.randint(2, 5)
		graph.init_semi_random(200, randomInternalConnections, randomCoacheesFactor)
		graphs.append(graph)
		filePath = os.path.join(folderPath, fileName)
		graph.save_as(filePath)
	return graphs
Example #26
0
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
Example #27
0
def test_add_students():
    graph = CoachingGraph()
    A = User()
    graph.add_user(A)

    graph.add_coachees(A, 10)

    assert len(A.coachees) == 10
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])
Example #29
0
def test_make_sparse_random_connections():
    graph = CoachingGraph()
    graph.create_and_add_users(20)
    graph.make_sparse_random_connections(5)

    numConnections = 0
    for user in graph.users:
        numConnections += len(user.coaches)
    assert numConnections == 5
Example #30
0
def resource_create_coach_coachee_relationship():
    graph = CoachingGraph()
    A = User()
    B = User()
    graph.add_user(A)
    graph.add_user(B)

    graph.create_coach_coachee_relationship(A, B)
    return A, B
Example #31
0
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
Example #32
0
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
Example #33
0
def generate_test_graphs_connected(dirName, numGraphs, maxSize):
    logger.info("generating test graphs in directory: {}".format(dirName))
    folderPath = refresh_testData_folder(dirName)

    for i in range(numGraphs):
        graph = CoachingGraph()

        fileNumber = i + 1
        fileName = '{}_'.format(fileNumber) + TEST_GRAPH_SUFFIX

        randomSize = random.randint(40, maxSize)
        graph.init_semi_random_connected(randomSize)

        filePath = os.path.join(folderPath, fileName)
        graph.save_as(filePath)
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
Example #35
0
def generate_test_graphs(dirName, numGraphs, maxSize):
    logger.info("generating test graphs in directory: {}".format(dirName))
    folderPath = refresh_testData_folder(dirName)
    graphs = []
    for i in range(numGraphs):
        graph = CoachingGraph()

        fileNumber = i + 1
        fileName = '{}_'.format(fileNumber) + TEST_GRAPH_SUFFIX

        randomSize = random.randint(100, maxSize)
        randomInternalConnections = random.randint(2, 12)
        randomCoacheesFactor = random.randint(2, 5)
        graph.init_semi_random(200, randomInternalConnections,
                               randomCoacheesFactor)
        graphs.append(graph)
        filePath = os.path.join(folderPath, fileName)
        graph.save_as(filePath)
    return graphs
Example #36
0
def test_random_graph():
    graph = CoachingGraph()
    graph.init_random(20)

    assert len(graph.users) == 20
def test_random_graph():
	graph = CoachingGraph()
	graph.init_random(20)

	assert len(graph.users) == 20
Example #38
0
def test_init_semi_random_connected():
    graph = CoachingGraph()
    graph.init_semi_random_connected(200)
    numSubgraphs = len(graphTraverser.get_subgraphs(graph.users))

    assert numSubgraphs == 1
def test_init_semi_random_connected():
	graph = CoachingGraph()
	graph.init_semi_random_connected(200)
	numSubgraphs = len(graphTraverser.get_subgraphs(graph.users))

	assert numSubgraphs == 1
Example #40
0
def resource_semi_random_graph_users():
	graph = CoachingGraph()
	graph.init_semi_random(200)

	return graph.users
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]
Example #42
0
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]