Skip to content

Commit

Permalink
Add tests for changed code and region aware
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrrock2 committed Jan 18, 2024
1 parent 5ad73d0 commit 1f184f4
Show file tree
Hide file tree
Showing 10 changed files with 1,904 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gerrychain/constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
no_worse_L_minus_1_polsby_popper)
from .contiguity import (contiguous, contiguous_bfs, no_more_discontiguous,
single_flip_contiguous)
from .validity import (Validator, districts_within_tolerance,
from .validity import (Validator, deviation_from_ideal, districts_within_tolerance,
no_vanishing_districts, refuse_new_splits,
within_percent_of_ideal_population)

Expand All @@ -56,5 +56,5 @@
"L_minus_1_polsby_popper", "no_worse_L1_reciprocal_polsby_popper",
"no_worse_L_minus_1_polsby_popper", "contiguous", "contiguous_bfs",
"no_more_discontiguous", "single_flip_contiguous", "Validator",
"districts_within_tolerance", "no_vanishing_districts",
"deviation_from_ideal", "districts_within_tolerance", "no_vanishing_districts",
"refuse_new_splits", "within_percent_of_ideal_population", "Bounds"]
8 changes: 7 additions & 1 deletion tests/constraints/test_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
contiguous, contiguous_bfs,
districts_within_tolerance,
no_vanishing_districts,
single_flip_contiguous)
single_flip_contiguous,
deviation_from_ideal)
from gerrychain.partition import Partition
from gerrychain.partition.partition import get_assignment
from gerrychain.graph import Graph
Expand Down Expand Up @@ -173,3 +174,8 @@ def test_no_vanishing_districts_works():
partition.assignment.update_flows({1: {"out": set(), "in": {2}}, 2: {"out": {2}, "in": set()}})

assert not no_vanishing_districts(partition)

def test_deviation_from_ideal():
mock_partition = {"population": {0: 99.0, 1: 101.0}}
assert deviation_from_ideal(mock_partition, "population") == \
{0: -0.01, 1: 0.01}
Binary file added tests/graphs_for_test/8x8_county.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/graphs_for_test/8x8_county2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/graphs_for_test/8x8_district.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/graphs_for_test/8x8_muni.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1f184f4

Please sign in to comment.