@@ -890,10 +890,9 @@ def test__negative_baseline_handled(self):
890890 assert not np .isnan (result ["all" ][label ])
891891 assert not np .isinf (result ["all" ][label ])
892892
893- def test__percentage_change_is_not_doubled (self ):
894- """Direct arithmetic check: a 2% gain must produce income_change
895- of 0.02, not 0.04. We verify via bucket assignment — 2% is well
896- within the <5% bucket."""
893+ def test__2pct_gain_is_not_doubled (self ):
894+ """A 2% gain stays in <5% even if doubled (2*2%=4% < 5%), so this
895+ test alone would not catch the doubling bug."""
897896 baseline = _make_economy (
898897 incomes = [50000.0 ] * 10 ,
899898 deciles = list (range (1 , 11 )),
@@ -904,12 +903,32 @@ def test__percentage_change_is_not_doubled(self):
904903 )
905904 result = intra_decile_impact (baseline , reform )
906905
907- # 2% gain must be in "Gain less than 5%", not "Gain more than 5%"
908906 for pct in result ["deciles" ]["Gain more than 5%" ]:
909907 assert pct == 0.0 , "2% gain incorrectly classified as >5%"
910908 for pct in result ["deciles" ]["Gain less than 5%" ]:
911909 assert pct == 1.0 , "2% gain not classified as <5%"
912910
911+ def test__4pct_gain_not_doubled_into_above_5pct (self ):
912+ """A 4% gain must stay in <5%. With the doubling bug, 4% * 2 = 8%
913+ would incorrectly land in >5%. This is the tightest regression
914+ test for the doubling bug on the gain side."""
915+ baseline = _make_economy (
916+ incomes = [10000.0 ] * 10 ,
917+ deciles = list (range (1 , 11 )),
918+ )
919+ reform = _make_economy (
920+ incomes = [10400.0 ] * 10 , # +4%
921+ deciles = list (range (1 , 11 )),
922+ )
923+ result = intra_decile_impact (baseline , reform )
924+
925+ for pct in result ["deciles" ]["Gain more than 5%" ]:
926+ assert (
927+ pct == 0.0
928+ ), "4% gain incorrectly classified as >5% (doubling bug)"
929+ for pct in result ["deciles" ]["Gain less than 5%" ]:
930+ assert pct == 1.0 , "4% gain not classified as <5%"
931+
913932 def test__all_field_averages_deciles (self ):
914933 """The 'all' field should be the mean of the 10 decile values."""
915934 baseline = _make_economy (
0 commit comments