本文整理汇总了Python中datastructures.array.Array.highest方法的典型用法代码示例。如果您正苦于以下问题:Python Array.highest方法的具体用法?Python Array.highest怎么用?Python Array.highest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datastructures.array.Array
的用法示例。
在下文中一共展示了Array.highest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reset
# 需要导入模块: from datastructures.array import Array [as 别名]
# 或者: from datastructures.array.Array import highest [as 别名]
def test_reset(self):
k = random.randint(1, 8)
highest = random.randint(-1, k - 1)
if highest == -1:
elements = [0] * k
else:
elements = [random.randint(0, 1) for _ in range(highest)] + [1] + [0] * (k - 1 - highest)
array = Array(elements, start=0)
array.highest = highest
reset(array)
actual_zero = bits_to_number(array.elements)
assert_that(actual_zero, is_(equal_to(0)))
assert_that(array.highest, is_(equal_to(-1)))
示例2: test_increment_
# 需要导入模块: from datastructures.array import Array [as 别名]
# 或者: from datastructures.array.Array import highest [as 别名]
def test_increment_(self):
k = random.randint(1, 8)
highest = random.randint(-1, k - 1)
if highest == -1:
elements = [0] * k
else:
elements = [random.randint(0, 1) for _ in range(highest)] + [1] + [0] * (k - 1 - highest)
array = Array(elements, start=0)
array.highest = highest
increment_(array)
actual_n_plus_1 = bits_to_number(array.elements)
n = bits_to_number(elements)
expected_n_plus_1 = (n + 1) % (2 ** k)
assert_that(actual_n_plus_1, is_(equal_to(expected_n_plus_1)))
if actual_n_plus_1 == 0:
assert_that(array.highest, is_(equal_to(-1)))
else:
assert_that(array.highest, is_(greater_than_or_equal_to(highest)))
assert_that(array[array.highest], is_(equal_to(1)))