Example #1
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}
    parts = tuple(set(assignment.values()))
    updaters = {"tally": DataTally(data, alias="tally")}
    partition = Partition(three_by_three_grid, assignment, updaters)

    flip = {random.choice(list(partition.graph.nodes)): random.choice(parts)}
    new_partition = partition.flip(flip)

    assert new_partition["tally"]
Example #2
0
def test_data_tally_gives_expected_value(three_by_three_grid):
    first_node = next(iter(three_by_three_grid.nodes))
    assignment = {node: 1 for node in three_by_three_grid.nodes}
    assignment[first_node] = 2

    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 = {first_node: 1}
    new_partition = partition.flip(flip)

    assert new_partition["tally"][1] == partition["tally"][1] + 1