Skip to content

Commit

Permalink
Allow zero value pKa in the Streamlit app
Browse files Browse the repository at this point in the history
  • Loading branch information
chicolucio committed Jul 27, 2022
1 parent aabf399 commit 3ab0f7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
22 changes: 16 additions & 6 deletions src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@ def next_smaller(lst):
last_item = None
i = 0
for index, item in enumerate(lst):
if item == 0:
break
if last_item is None or (item >= last_item and index == i):
last_item = item
i += 1
yield item


def valid_pka_values(values):
"""
This function filters possible pKa values for the app web page.
It's perfectly fine negative pKa values and non-sorted values in real life
but is not so usual. Then, for educational purposes, it was decided to
create this filter.
Parameters
----------
values : tuple
Returns
-------
list
"""
values = list(values)
result = []
if values[0] == 0:
pass
elif is_sorted(values):
if is_sorted(values):
result = values
else:
result = list(next_smaller(values))
Expand Down
12 changes: 8 additions & 4 deletions tests/test_valid_pka_values.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from src.helpers import valid_pka_values


def test_three_inputs_no_pka():
assert valid_pka_values((0, 0, 0)) == []
def test_three_zero_inputs_three_pka():
assert valid_pka_values((0, 0, 0)) == [0, 0, 0]


def test_three_inputs_one_pka():
Expand All @@ -21,14 +21,18 @@ def test_three_inputs_equal():
assert valid_pka_values((1, 1, 1)) == [1, 1, 1]


def test_four_inputs_no_pka():
assert valid_pka_values((0, 0, 0, 0)) == []
def test_four_zero_inputs_four_pka():
assert valid_pka_values((0, 0, 0, 0)) == [0, 0, 0, 0]


def test_three_inputs_sorted():
assert valid_pka_values((1, 2, 3)) == [1, 2, 3]


def test_three_inputs_sorted_first_zero():
assert valid_pka_values((0, 2, 3)) == [0, 2, 3]


def test_three_inputs_sorted_two_equal():
assert valid_pka_values((1, 2, 2)) == [1, 2, 2]

Expand Down

0 comments on commit 3ab0f7c

Please sign in to comment.