verify/AI/staticbitset_test.nim

This documentation is automatically generated by online-judge-tools/verification-helper

:heavy_check_mark: verify/AI/staticbitset_test.nim

Depends on

Code

# verification-helper: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_A
echo "Hello World"

import cplib/collections/staticbitset

assert (~initBitSet(0)).popcount() == 0

var a = initBitSet(@[true, false, true, false, true], 70)
var b = initBitSetFromIndexes(@[2, 4, 65], 70)
var bItems: seq[int]
for i in b:
    bItems.add(i)
assert bItems == @[2, 4, 65]
assert b.lowestBit == 2
assert initBitSet(70).lowestBit == -1
assert a[0]
assert not a[1]
assert a.popcount() == 3
assert b.popcount() == 3
assert (a & b).popcount() == 2
assert (a | b).popcount() == 4
assert (a ^ b).popcount() == 2
assert a.andpopcount(b) == 2
assert a.orpopcount(b) == 4
assert a.xorpopcount(b) == 2
a &= b
assert a.popcount() == 2
a |= b
assert a.popcount() == 3
a ^= b
assert a.popcount() == 0
a[69] = 1
assert a[69]
assert (a << 1).popcount() == 0
a[69] = 0
a[1] = true
assert (a << 2)[3]
assert (a >> 1)[0]
assert (~initBitSet(5)).popcount() == 5
assert $initBitSet(@[true, false, true], 3) == "101"

proc checkLeftShift[size: static int]() =
    ## 各位置の単一ビットを全シフト幅で動かし、桁上がりと切り捨てを検証します。
    for position in 0..<size:
        let x = initBitSetFromIndexes([position], size)
        for shift in 0..size + 1:
            let shifted = x << shift
            if position + shift < size:
                assert shifted.popcount == 1
                assert shifted[position + shift]
            else:
                assert shifted.popcount == 0
        assert (x << int.high).popcount == 0
    assert (initBitSet(size) << 63).popcount == 0

checkLeftShift[0]()
checkLeftShift[1]()
checkLeftShift[63]()
checkLeftShift[64]()
checkLeftShift[65]()
checkLeftShift[128]()
checkLeftShift[129]()
checkLeftShift[257]()
Traceback (most recent call last):
  File "/home/runner/.local/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.local/lib/python3.12/site-packages/onlinejudge_verify/languages/nim.py", line 86, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page