From 973ac42a9766a75a72a102125ddc0652aa065ed9 Mon Sep 17 00:00:00 2001 From: Al Date: Sun, 31 Jul 2016 22:29:21 -0400 Subject: [PATCH] [test] Checking probability distributions as part of the address config tests --- scripts/geodata/tests/test_address_configs.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/geodata/tests/test_address_configs.py b/scripts/geodata/tests/test_address_configs.py index 8998efdd..362c6356 100644 --- a/scripts/geodata/tests/test_address_configs.py +++ b/scripts/geodata/tests/test_address_configs.py @@ -11,6 +11,8 @@ from geodata.addresses.staircases import * from geodata.addresses.units import * from geodata.categories.query import * +from geodata.math.floats import isclose + invalid_phrase_re = re.compile(r'\b(None|False|True)\b') @@ -19,6 +21,18 @@ class TestAddressConfigs(unittest.TestCase): def valid_phrase(self, phrase): return phrase is None or not invalid_phrase_re.search(phrase) + def check_components(self, language, country): + conf = address_config.get_property('components', language, country=country) + for component, value in six.iteritems(conf): + if component == 'combinations': + continue + total_prob = 0.0 + for k, v in six.iteritems(value): + if k.endswith('probability'): + total_prob += v + + self.assertTrue(isclose(total_prob, 1.0), six.u('language: {}, country: {}, component: {}'.format(language, country, component))) + def check_entrance_phrases(self, language, country=None): for i in xrange(1000): phrase = Entrance.phrase(Entrance.random(language, country=country), language, country=country) @@ -68,6 +82,8 @@ class TestAddressConfigs(unittest.TestCase): def check_config(self, language, country=None): print('Doing lang={}, country={}'.format(language, country)) + print('Checking components') + self.check_components(language, country=country) print('Checking entrances') self.check_entrance_phrases(language, country=country) print('Checking staircases')