Skip to content

Commit

Permalink
Merge pull request #10 from AndrewLane/newline-formatting-improvements
Browse files Browse the repository at this point in the history
Formatting improvements
  • Loading branch information
AndrewLane authored Dec 31, 2020
2 parents 47fd84b + 639db1f commit 001d9aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}
6 changes: 2 additions & 4 deletions benfords_law_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
12 changes: 3 additions & 9 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,22 @@ 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
assert(counts) == [1] * 9


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%
Expand Down

0 comments on commit 001d9aa

Please sign in to comment.