Skip to content

Commit

Permalink
Greatly increased test coverage
Browse files Browse the repository at this point in the history
Increased test coverage and changed main function name to make it shorter
  • Loading branch information
Feelx234 authored Oct 25, 2023
2 parents 238a143 + 1c26a9b commit 9364f12
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
# .coveragerc to control coverage.py
[run]
branch = True
Expand Down Expand Up @@ -31,3 +32,4 @@ omit =
*/algorithms_educational.py
*/algorithms_old.py
*/smawk_old.py
*/utils_for_test.py
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[MASTER]
disable= missing-module-docstring, missing-class-docstring, missing-function-docstring, missing-final-newline, C0325
ignore-paths=.coveragerc
ignore=.coveragerc
[FORMAT]
max-line-length=200

# allow 1 or 2 length variable names
good-names-rgxs=^[_a-zGW][_a-z0-9L]?$
good-names=R,D,T,D_row,S,A,F,H,F_vals, F_val, H_vals, M, SMALL_VAL, LARGE_VAL, MicroaggWilberCalculator_edu, N_vals, N
good-names=R,D,T,D_row,S,A,F,H,F_vals, F_val, H_vals, M, SMALL_VAL, LARGE_VAL, MicroaggWilberCalculator_edu, N_vals, N, setUp, tearDown
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ testpaths = tests
# slow: mark tests as slow (deselect with '-m "not slow"')
# system: mark end-to-end system tests

[tool.pylint.MASTER]
ignore = .coveragerc
ignore-paths = .coveragerc

[devpi:upload]
# Options for the devpi: PyPI server and packaging tool
# VCS export must be deactivated since we are using setuptools-scm
Expand Down Expand Up @@ -162,3 +166,4 @@ omit =
*/algorithms_educational.py
*/algorithms_old.py
*/smawk_old.py
*/utils_for_test.py
4 changes: 2 additions & 2 deletions src/microagg1d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from microagg1d.main import optimal_univariate_microaggregation_1d
from microagg1d.main import univariate_microaggregation

microagg1d = optimal_univariate_microaggregation_1d # shorthand for the above
microagg1d = univariate_microaggregation # shorthand for the above
2 changes: 1 addition & 1 deletion src/microagg1d/cost_maxdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, arr, k, F_vals):
self.SMALL_VAL = (arr[-1] - arr[0]) * n
self.LARGE_VAL = self.SMALL_VAL * (1 + n)

def calc(self, i, j): # i <-> j interchanged is not a bug!
def calc(self, i, j):
"""This function computes the w_{ij} values introduced"""
if j <= i:
return np.inf
Expand Down
4 changes: 2 additions & 2 deletions src/microagg1d/cost_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, arr, k, F_vals):
self.SMALL_VAL = (arr[-1] - arr[0]) * n
self.LARGE_VAL = self.SMALL_VAL * (1 + n)

def calc(self, i, j): # i <-> j interchanged is not a bug!
def calc(self, i, j):
"""This function computes the w_{ij} values introduced"""
if j <= i:
return np.inf
Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self, arr, k, F_vals):
self.SMALL_VAL = (arr[-1] - arr[0]) * n
self.LARGE_VAL = self.SMALL_VAL * (1 + n)

def calc(self, i, j): # i <-> j interchanged is not a bug!
def calc(self, i, j):
"""This function computes the w_{ij} values introduced"""
if j <= i:
return np.inf
Expand Down
2 changes: 1 addition & 1 deletion src/microagg1d/cost_sae.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, arr, k, F_vals):
self.SMALL_VAL = (arr[-1] - arr[0]) * n
self.LARGE_VAL = self.SMALL_VAL * (1 + n)

def calc(self, i, j): # i <-> j interchanged is not a bug!
def calc(self, i, j):
"""This function computes the w_{ij} values introduced"""
if j <= i:
return np.inf
Expand Down
2 changes: 1 addition & 1 deletion src/microagg1d/cost_sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def compute_sse_sorted_stable(v, clusters_sorted):
r = 0
while r < len(v):
r = left
while clusters_sorted[left] == clusters_sorted[r] and r < len(v):
while r < len(v) and clusters_sorted[left] == clusters_sorted[r]:
r += 1
# r-=1
mean = np.mean(v[left:r])
Expand Down
4 changes: 3 additions & 1 deletion src/microagg1d/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def undo_argsort(sorted_arr, sort_order):
return sorted_arr[revert]


def optimal_univariate_microaggregation_1d(x, k, method="auto", stable=1, cost="sse"):
def univariate_microaggregation(x, k, method="auto", stable=1, cost="sse"):
"""Performs optimal 1d univariate microaggregation"""
x = np.squeeze(np.asarray(x))
assert len(x.shape) == 1, "provided array is not 1d"
Expand Down Expand Up @@ -70,4 +70,6 @@ def optimal_univariate_microaggregation_1d(x, k, method="auto", stable=1, cost="
clusters = _rounddown_user(x, k, method)
elif cost == "maxdist":
clusters = _maxdist_user(x, k, method)
else:
raise NotImplementedError("Should not be reachable")
return undo_argsort(clusters, order)
Loading

0 comments on commit 9364f12

Please sign in to comment.