From 639db1fefe6d954f5f18107e6352364bd4679688 Mon Sep 17 00:00:00 2001 From: Andrew Lane Date: Wed, 30 Dec 2020 19:36:03 -0500 Subject: [PATCH] Formatting improvements --- .vscode/settings.json | 3 ++- benfords_law_utils/utils.py | 6 ++---- tests/test_utils.py | 12 +++--------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b20f04d..4c0f3f6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,6 @@ "titleBar.activeForeground": "#FAFBFA" }, "python.linting.pycodestyleEnabled": true, - "python.linting.enabled": true + "python.linting.enabled": true, + "python.linting.pycodestyleArgs": ["--max-line-length=120"], } \ No newline at end of file diff --git a/benfords_law_utils/utils.py b/benfords_law_utils/utils.py index 6329a30..a1a7258 100644 --- a/benfords_law_utils/utils.py +++ b/benfords_law_utils/utils.py @@ -3,8 +3,7 @@ def calculate_benford_stats(numerical_data): first_digit_index = 0 - first_digits = list(map( - lambda number: int(str(number)[first_digit_index]), numerical_data)) + first_digits = list(map(lambda number: int(str(number)[first_digit_index]), numerical_data)) total_count = 0 empirical_counts = [0, 0, 0, 0, 0, 0, 0, 0, 0] @@ -25,8 +24,7 @@ def ascii_art_bar_graph(ratios, max_width): max_value = max(ratios) - benford_ratios = [0.30103, 0.176091, 0.124939, 0.09691, 0.0791812, - 0.0669468, 0.0579919, 0.0511525, 0.0457575] + benford_ratios = [0.30103, 0.176091, 0.124939, 0.09691, 0.0791812, 0.0669468, 0.0579919, 0.0511525, 0.0457575] if benford_ratios[0] > max_value: max_value = benford_ratios[0] diff --git a/tests/test_utils.py b/tests/test_utils.py index 9b32b95..41c0d2a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -19,9 +19,7 @@ def test_calculate_benford_stats_for_single_input(): def test_calculate_benford_stats_for_uniform_input(): - counts, ratios, total_count = calculate_benford_stats( - [111, 222, 333, 444, 555, 666, 777, 888, 999] - ) + counts, ratios, total_count = calculate_benford_stats([111, 222, 333, 444, 555, 666, 777, 888, 999]) assert(total_count) == 9 expected_ratio = 1 / 9 assert(ratios) == [expected_ratio] * 9 @@ -29,18 +27,14 @@ def test_calculate_benford_stats_for_uniform_input(): def test_calculate_benford_stats_for_simple_input(): - counts, ratios, total_count = calculate_benford_stats( - [111, 3000, 701234, 8675309, 8888] - ) + counts, ratios, total_count = calculate_benford_stats([111, 3000, 701234, 8675309, 8888]) assert(total_count) == 5 assert(ratios) == [.2, 0, .2, 0, 0, 0, .2, .4, 0] assert(counts) == [1, 0, 1, 0, 0, 0, 1, 2, 0] def test_ascii_art_bar_graph(): - _, ratios, __ = calculate_benford_stats( - [111, 3000, 701234, 8675309, 8888] - ) + _, ratios, __ = calculate_benford_stats([111, 3000, 701234, 8675309, 8888]) bar_graph = ascii_art_bar_graph(ratios, 20) assert(bar_graph) == """********** Leading 1 Ratio: 20.000% ^ Expected Ratio: 30.103%