예제 #1
0
def test_data_tally_gives_expected_value(three_by_three_grid):
    assignment = {node: 1 for node in three_by_three_grid.nodes}
    data = {node: 1 for node in three_by_three_grid}
    updaters = {'tally': DataTally(data, alias='tally')}
    partition = Partition(three_by_three_grid, assignment, updaters)

    flip = {list(three_by_three_grid.nodes)[0]: 0}
    new_partition = partition.merge(flip)

    assert new_partition['tally'][1] == partition['tally'][1] - 1
예제 #2
0
def test_data_tally_works_as_an_updater(three_by_three_grid):
    assignment = random_assignment(three_by_three_grid, 4)
    data = {node: random.randint(1, 100) for node in three_by_three_grid.nodes}
    updaters = {'tally': DataTally(data, alias='tally')}
    partition = Partition(three_by_three_grid, assignment, updaters)

    flip = {
        random.choice(list(partition.graph.nodes)): random.choice(range(4))
    }
    new_partition = partition.merge(flip)

    assert new_partition['tally']
예제 #3
0
def test_Partition_can_update_stats():
    graph = networkx.complete_graph(3)
    assignment = {0: 1, 1: 1, 2: 2}

    graph.nodes[0]['stat'] = 1
    graph.nodes[1]['stat'] = 2
    graph.nodes[2]['stat'] = 3

    updaters = {'total_stat': Tally('stat', alias='total_stat')}

    partition = Partition(graph, assignment, updaters)
    assert partition['total_stat'][2] == 3
    flip = {1: 2}

    new_partition = partition.merge(flip)
    assert new_partition['total_stat'][2] == 5