Skip to content

Commit

Permalink
better naming for digits generating funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
milcent committed Apr 17, 2021
1 parent 99a873a commit 87c64c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions benford/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class First(DataFrame):
def __init__(self, digs, plot=True, save_plot=None, save_plot_kwargs=None):
_check_digs_(digs)
dig_name = f'First_{digs}_Dig'
exp_array, dig_array = _gen_digits_(digs)
exp_array, dig_array = _gen_first_digits_(digs)

DataFrame.__init__(self, {'Expected': exp_array}, index=dig_array)
self.index.names = [dig_name]
Expand Down Expand Up @@ -85,7 +85,7 @@ class LastTwo(DataFrame):
figure file path/name.
"""
def __init__(self, num=False, plot=True, save_plot=None, save_plot_kwargs=None):
exp, l2d = _gen_l2d_(num=num)
exp, l2d = _gen_last_two_digits_(num=num)
DataFrame.__init__(self, {'Expected': exp,
'Last_2_Dig': l2d})
self.set_index('Last_2_Dig', inplace=True)
Expand All @@ -111,7 +111,7 @@ def _get_expected_digits_(digs):
return LastTwo(num=True, plot=False)


def _gen_l2d_(num=False):
def _gen_last_two_digits_(num=False):
"""Creates two arrays, one with the possible last two digits and one with
thei respective probabilities
Expand All @@ -134,7 +134,7 @@ def _gen_l2d_(num=False):
'06', '07', '08', '09'])
return exp, l2d

def _gen_digits_(digs):
def _gen_first_digits_(digs):
"""Creates two arrays, one with the possible digits combinations and the
other with their respective expected probabilities according to Benford
Expand All @@ -158,7 +158,7 @@ def _gen_second_digits_():
(tuple of arrays): the expected probabilities array and the second
digits array.
"""
exp_f2d, _ = _gen_digits_(2)
exp_f2d, _ = _gen_first_digits_(2)
sec_digs = range(10)
sec_digs_in_f2d = array(list(range(10)) * 9)
exp = array([exp_f2d[sec_digs_in_f2d == i].sum() for i in sec_digs])
Expand Down
16 changes: 8 additions & 8 deletions tests/test_expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,39 @@ def test_minus_2(self):
assert len(f1d) == 100


class TestGenL2d():
class TestGenLastTwoDigits():

def test_l2d_num_False(self):
_, lt = ex._gen_l2d_()
_, lt = ex._gen_last_two_digits_()
assert len(lt) == 100
assert lt.dtype == '<U21'

def test_l2d_num_True(self):
_, lt = ex._gen_l2d_(num=True)
_, lt = ex._gen_last_two_digits_(num=True)
assert len(lt) == 100
assert lt.dtype == 'int'

def test_exp(self):
exp, _ = ex._gen_l2d_()
exp, _ = ex._gen_last_two_digits_()
assert len(exp == 100)
assert exp.sum() > 0.999999

class TestGenDigits():
class TestGenFirstDigits():

def test_f1d(self):
exp, digits = ex._gen_digits_(1)
exp, digits = ex._gen_first_digits_(1)
assert len(exp) == len(digits) == 9
assert exp.sum() > 0.999999
assert digits.sum() == 45

def test_f2d(self):
exp, digits = ex._gen_digits_(2)
exp, digits = ex._gen_first_digits_(2)
assert len(exp) == len(digits) == 90
assert exp.sum() > 0.999999
assert digits.sum() == 4905

def test_f3d(self):
exp, digits = ex._gen_digits_(3)
exp, digits = ex._gen_first_digits_(3)
assert len(exp) == len(digits) == 900
assert exp.sum() > 0.999999
assert digits.sum() == 494550
Expand Down

0 comments on commit 87c64c5

Please sign in to comment.