From 2e14944d9ac8ec85db6aedc3100cd2377e78804b Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sat, 9 Mar 2024 15:52:33 +0100 Subject: [PATCH] tests(#144): test comprehensions Fixes #144 --- iterpy/test_arr.py | 12 ++++++++++++ iterpy/test_iter.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/iterpy/test_arr.py b/iterpy/test_arr.py index b2fb4e7..5a0c1b7 100644 --- a/iterpy/test_arr.py +++ b/iterpy/test_arr.py @@ -138,6 +138,18 @@ def test_flatten(): assert result.to_list() == [1, 2, 3, 4] +def test_comphrehension(): + test_iterator = Arr([1, 2, 3]) + result = [i for i in test_iterator if i % 2 == 0] + assert result == [2] + + +def test_looping(): + test_iterator = Arr([1, 2, 3]) + for i in test_iterator: + assert i in [1, 2, 3] + + @pytest.mark.benchmark() def test_benchmark_large_flattening(): test_input = Arr(range(100_000)).map(lambda x: Arr([x])) diff --git a/iterpy/test_iter.py b/iterpy/test_iter.py index e7efaf7..53965eb 100644 --- a/iterpy/test_iter.py +++ b/iterpy/test_iter.py @@ -137,6 +137,18 @@ def test_flatten(): assert result.to_list() == [1, 2, 3, 4] +def test_comphrehension(): + test_iterator = Iter([1, 2, 3]) + result = [i for i in test_iterator if i % 2 == 0] + assert result == [2] + + +def test_looping(): + test_iterator = Iter([1, 2, 3]) + for i in test_iterator: + assert i in [1, 2, 3] + + @pytest.mark.benchmark() def test_benchmark_large_flattening(): test_input = Iter(range(100_000)).map(lambda x: Iter([x]))