Skip to content

Commit

Permalink
Add tests for update order consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
bamartin125 committed Oct 20, 2020
1 parent 8943e75 commit 2c46e47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tests/test_coverage_sortedkeylist_modulo.py
Expand Up @@ -5,6 +5,7 @@
import random
from .context import sortedcontainers
from sortedcontainers import SortedList, SortedKeyList
from itertools import chain, repeat
import pytest

if hexversion < 0x03000000:
Expand Down Expand Up @@ -107,6 +108,18 @@ def test_update():
assert len(slt) == 11000
slt._check()

def test_update_order_consistency():
slt = SortedKeyList(key=lambda x: x[0])

it1 = list(zip(repeat(0), range(4)))
it2 = list(zip(repeat(0), range(5)))

slt.update(it1)
slt.update(it2)
slt._check()

assert all(tup[0] == tup[1] for tup in zip(slt, chain(it1, it2)))

def test_contains():
slt = SortedKeyList(key=modulo)
slt._reset(7)
Expand Down
14 changes: 13 additions & 1 deletion tests/test_coverage_sortedkeylist_negate.py
Expand Up @@ -5,7 +5,7 @@
import random
from .context import sortedcontainers
from sortedcontainers import SortedKeyList, SortedListWithKey
from itertools import chain
from itertools import chain, repeat
import pytest

if hexversion < 0x03000000:
Expand Down Expand Up @@ -84,6 +84,18 @@ def test_update():
values = sorted((val for val in chain(range(100), range(1000), range(10000))), key=negate)
assert all(tup[0] == tup[1] for tup in zip(slt, values))

def test_update_order_consistency():
slt = SortedKeyList(key=lambda x: x[0])

it1 = list(zip(repeat(0), range(4)))
it2 = list(zip(repeat(0), range(5)))

slt.update(it1)
slt.update(it2)
slt._check()

assert all(tup[0] == tup[1] for tup in zip(slt, chain(it1, it2)))

def test_contains():
slt = SortedKeyList(key=negate)
assert 0 not in slt
Expand Down

0 comments on commit 2c46e47

Please sign in to comment.