本文整理汇总了Python中intset.IntSet类的典型用法代码示例。如果您正苦于以下问题:Python IntSet类的具体用法?Python IntSet怎么用?Python IntSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IntSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_builder_insert_intervals_equivalent_to_successive_union
def test_builder_insert_intervals_equivalent_to_successive_union(intervals):
builder = IntSet.Builder()
equiv = IntSet.empty()
for ij in intervals:
equiv |= IntSet.interval(*ij)
builder.insert_interval(*ij)
assert builder.build() == equiv
示例2: test_sequentially_removing_intervals_yields_empty
def test_sequentially_removing_intervals_yields_empty(ls):
running = IntSet.from_intervals(ls)
for i in ls:
inter = IntSet.interval(*i)
extra = inter & running
original = running.size()
assert (running - inter) == (running - extra)
running -= inter
assert running.size() == original - extra.size()
assert running.size() == 0
示例3: test_deepcopy_collapses_reference_equality
def test_deepcopy_collapses_reference_equality():
x = IntSet.from_iterable([1, 2, 3])
y = IntSet.from_iterable([1, 2, 3])
z = IntSet.from_iterable([1, 2, 3, 4])
assert x == y
assert x is not y
w, u, v = deepcopy((x, y, z))
assert x == w
assert y == u
assert z == v
assert w is u
assert w is not v
示例4: test_insert_into_interval
def test_insert_into_interval(bounds, ints):
imp = IntSet.interval(*bounds)
for i in ints:
imp = imp.insert(i)
assert i in imp
for i in ints:
assert i in imp
示例5: test_is_equal_to_random_insertion
def test_is_equal_to_random_insertion(imp, rnd):
items = list(imp)
rnd.shuffle(items)
equiv = IntSet.empty()
for i in items:
equiv = equiv.insert(i)
assert imp == equiv
示例6: test_validates_bounds
def test_validates_bounds():
with pytest.raises(ValueError):
IntSet.single(-1)
with pytest.raises(ValueError):
IntSet.single(2 ** 64)
with pytest.raises(ValueError):
IntSet.interval(1, 2 ** 65)
with pytest.raises(ValueError):
IntSet.interval(2 ** 65, 1)
示例7: three_adjacent_values
def three_adjacent_values(self, v):
assume(v + 2 <= 2 ** 64)
return (IntSet.interval(v, v + 3), [v, v + 1, v + 2])
示例8: single_value
def single_value(self, v):
return (IntSet.single(v), [v])
示例9: adjacent_values
def adjacent_values(self, v):
assume(v + 1 <= 2 ** 64)
return (IntSet.interval(v, v + 2), [v, v + 1])
示例10: test_not_equal_to_other_types
def test_not_equal_to_other_types():
assert IntSet.single(1) != 1
示例11: build_interval
def build_interval(self, bounds):
return (IntSet.interval(*bounds), list(range(*bounds)))
示例12: test_can_produce_whole_range_intset
def test_can_produce_whole_range_intset():
assert IntSet.interval(0, 2 ** 64).size() == 2 ** 64
示例13: insert_interval
def insert_interval(self, ij):
self.builder.insert_interval(*ij)
self.equivalent = self.equivalent | IntSet.interval(*ij)
示例14: three_adjacent_values_with_hole
def three_adjacent_values_with_hole(self, v):
assume(v + 2 <= 2 ** 64)
return (IntSet.single(v) | IntSet.single(v + 2), [v, v + 2])
示例15: test_concatenation_of_lists_is_union
def test_concatenation_of_lists_is_union(x, y):
assert IntSet.from_intervals(x + y) == \
IntSet.from_intervals(x) | IntSet.from_intervals(y)