-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(message-queue/python): SampleIterator
its ugly but its an interesting question of 1. if genrator or iterator is preferred. 2. why is not working.
- Loading branch information
1 parent
9e79e8c
commit 2663a55
Showing
2 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
from jmcgmqp.algorithm import find_maximum, Sampler | ||
from jmcgmqp.algorithm import find_maximum, Sampler, SampleIterator | ||
|
||
from unittest.mock import create_autospec, call | ||
import pytest | ||
|
||
@pytest.mark.parametrize('sequence, result, args, power', ( | ||
cases = ( | ||
((1, 1, 1), 1, (1, 2), 0), | ||
((1, 2, 1, 1), 2, (1, 2, 4, 3), 0), | ||
((1, 2, 1, 3), 3, (1, 2, 4, 3), 0), | ||
((1, 2, 3, 4, 5, 1, 1), 5, (1, 2, 4, 8, 16, 32, 17), 0), | ||
((1, 2, 3, 1, 4, 5, 1), 5, (1, 2, 4, 8, 5, 6, 7), 0), | ||
((1, 1, 1), 1, (4, 8, 5), 2), | ||
)) | ||
) | ||
|
||
@pytest.mark.parametrize('sequence, result, args, power', cases) | ||
def test_find_maximum(sequence, result, args, power): | ||
sample = create_autospec(Sampler, spec_set=True) | ||
sample.side_effect = sequence | ||
assert find_maximum(sample, power) == result | ||
assert sample.call_args_list == [call(x) for x in args] | ||
|
||
@pytest.mark.parametrize('sequence, result, args, power', cases) | ||
def test_SampleIterator(sequence, result, args, power): | ||
sample = create_autospec(Sampler, spec_set=True) | ||
sample.side_effect = sequence | ||
assert next(SampleIterator(sample, power)) == args[0] | ||
return | ||
assert tuple(SampleIterator(sample, power)) == args |