From e232950d46dd7aa92624825e0cd461425b037f8a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 16 Sep 2020 14:14:41 +0100 Subject: [PATCH] Add tests for the population calculations Now that this function is split out we can unit test it to make sure that the expected numbers are coming out of it. --- .../broadcast_areas/test_broadcast_area.py | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/tests/app/broadcast_areas/test_broadcast_area.py b/tests/app/broadcast_areas/test_broadcast_area.py index 1c4e93925..1fc4d5f60 100644 --- a/tests/app/broadcast_areas/test_broadcast_area.py +++ b/tests/app/broadcast_areas/test_broadcast_area.py @@ -4,7 +4,10 @@ from app.broadcast_areas import ( BroadcastAreasRepository, broadcast_area_libraries, ) -from app.broadcast_areas.populations import CITY_OF_LONDON +from app.broadcast_areas.populations import ( + CITY_OF_LONDON, + estimate_number_of_smartphones_for_population, +) def test_loads_libraries(): @@ -176,3 +179,60 @@ def test_city_of_london_counts_are_not_derived_from(): # count of phones is much larger, because it isn’t derived from # the resident population. assert ward.count_of_phones > 5_000 + + +@pytest.mark.parametrize('population, expected_estimate', ( + # Upper and lower bounds of each age range + ( + [(0, 100)], 50, + ), + ( + [(16, 100)], 100 + ), + ( + [(24, 100)], 100, + ), + ( + [(25, 100)], 97, + ), + ( + [(34, 100)], 97, + ), + ( + [(35, 100)], 91 + ), + ( + [(44, 100)], 91, + ), + ( + [(45, 100)], 88 + ), + ( + [(54, 100)], 88, + ), + ( + [(55, 100)], 73 + ), + ( + [(64, 100)], 73, + ), + ( + [(65, 100)], 40 + ), + ( + [(999, 100)], 40, + ), + # Multiple different ages in a single popualtion + ( + [(16, 100), (54, 100)], 188 + ), + ( + [(1, 1000), (66, 100)], 540 + ), +)) +def test_estimate_number_of_smartphones_for_population( + population, expected_estimate, +): + assert estimate_number_of_smartphones_for_population( + population + ) == expected_estimate