From 2c46e4765813bb46998619c2458db89f2c9ef903 Mon Sep 17 00:00:00 2001 From: "Brock A. Martin" Date: Tue, 20 Oct 2020 10:41:56 -0500 Subject: [PATCH] Add tests for update order consistency --- tests/test_coverage_sortedkeylist_modulo.py | 13 +++++++++++++ tests/test_coverage_sortedkeylist_negate.py | 14 +++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test_coverage_sortedkeylist_modulo.py b/tests/test_coverage_sortedkeylist_modulo.py index 1916054f..fc612a07 100644 --- a/tests/test_coverage_sortedkeylist_modulo.py +++ b/tests/test_coverage_sortedkeylist_modulo.py @@ -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: @@ -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) diff --git a/tests/test_coverage_sortedkeylist_negate.py b/tests/test_coverage_sortedkeylist_negate.py index 6c0287f8..2bacfd7f 100644 --- a/tests/test_coverage_sortedkeylist_negate.py +++ b/tests/test_coverage_sortedkeylist_negate.py @@ -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: @@ -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