Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong result if lookup_value is string for "match" function. #148

Open
lhz5166 opened this issue May 5, 2022 · 1 comment
Open

Wrong result if lookup_value is string for "match" function. #148

lhz5166 opened this issue May 5, 2022 · 1 comment

Comments

@lhz5166
Copy link

lhz5166 commented May 5, 2022

Problem description

When I match the string value, the result is incorrect.

What actually happened

============================= test session starts =============================
collecting ... collected 3 items

test_lookup.py::test_match_for_string[1-lookup_array0-1-3] 
test_lookup.py::test_match_for_string[B-lookup_array1-1-3] PASSED        [ 33%]FAILED        [ 66%]
tests\lib\test_lookup.py:403 (test_match_for_string[B-lookup_array1-1-3])
5 != 3

Expected :3
Actual   :5
<Click to see difference>

lookup_value = 'B', lookup_array = ['A', None, 'B', None, 'C', None, ...]
match_type = 1, expected = 3

    @pytest.mark.parametrize(
        'lookup_value, lookup_array, match_type, expected', (
            (1, [None, None, 1, 3.3, 5, None, None], 1, 3),
            ('B', ['A', None, 'B', None, 'C', None, 'D'], 1, 3),
            (1, [2, None, 1, 3.3, 5, None, None], 1, 3),
        ))
    def test_match_for_string(lookup_value, lookup_array, match_type, expected):
        lookup_row = (tuple(lookup_array),)
        lookup_col = tuple((i,) for i in lookup_array)
>       assert match(lookup_value, lookup_row, match_type) == expected
E       AssertionError: assert 5 == 3
E        +  where 5 = match('B', (('A', None, 'B', None, 'C', None, ...),), 1)

test_lookup.py:413: AssertionError
PASSED        [100%]






test_lookup.py::test_match_for_string[1-lookup_array2-1-3] 

=================== 1 failed, 2 passed, 1 warning in 0.29s ====================
@lhz5166
Copy link
Author

lhz5166 commented May 5, 2022

It looks not a problem, it's a misuse of "bisect_right()"

array
Out[13]: ('A', None, 'B', None, 'C', None, 'D')
value
Out[14]: ExcelCmp(cmp_type=1, value='A', empty='')
bisect_right(array, value, lo=0, hi=len(array))
Out[15]: 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant