Skip to content

Commit 1f184f4

Browse files
committed
Add tests for changed code and region aware
1 parent 5ad73d0 commit 1f184f4

10 files changed

+1904
-7
lines changed

gerrychain/constraints/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
no_worse_L_minus_1_polsby_popper)
4646
from .contiguity import (contiguous, contiguous_bfs, no_more_discontiguous,
4747
single_flip_contiguous)
48-
from .validity import (Validator, districts_within_tolerance,
48+
from .validity import (Validator, deviation_from_ideal, districts_within_tolerance,
4949
no_vanishing_districts, refuse_new_splits,
5050
within_percent_of_ideal_population)
5151

@@ -56,5 +56,5 @@
5656
"L_minus_1_polsby_popper", "no_worse_L1_reciprocal_polsby_popper",
5757
"no_worse_L_minus_1_polsby_popper", "contiguous", "contiguous_bfs",
5858
"no_more_discontiguous", "single_flip_contiguous", "Validator",
59-
"districts_within_tolerance", "no_vanishing_districts",
59+
"deviation_from_ideal", "districts_within_tolerance", "no_vanishing_districts",
6060
"refuse_new_splits", "within_percent_of_ideal_population", "Bounds"]

tests/constraints/test_validity.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
contiguous, contiguous_bfs,
99
districts_within_tolerance,
1010
no_vanishing_districts,
11-
single_flip_contiguous)
11+
single_flip_contiguous,
12+
deviation_from_ideal)
1213
from gerrychain.partition import Partition
1314
from gerrychain.partition.partition import get_assignment
1415
from gerrychain.graph import Graph
@@ -173,3 +174,8 @@ def test_no_vanishing_districts_works():
173174
partition.assignment.update_flows({1: {"out": set(), "in": {2}}, 2: {"out": {2}, "in": set()}})
174175

175176
assert not no_vanishing_districts(partition)
177+
178+
def test_deviation_from_ideal():
179+
mock_partition = {"population": {0: 99.0, 1: 101.0}}
180+
assert deviation_from_ideal(mock_partition, "population") == \
181+
{0: -0.01, 1: 0.01}

tests/graphs_for_test/8x8_county.png

35.1 KB
Loading

tests/graphs_for_test/8x8_county2.png

46.3 KB
Loading
60.6 KB
Loading

tests/graphs_for_test/8x8_muni.png

54.5 KB
Loading

0 commit comments

Comments
 (0)