Created
April 19, 2022 23:03
-
-
Save RyanKor/3a5b6020dd7c3b0a7771f10f0151bed9 to your computer and use it in GitHub Desktop.
vb code 테스트
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.path.append('vb_code.py 경로 추가하거나, 동일 경로상에 두고 테스트 수행하기') | |
import vb | |
from struct import unpack | |
import random | |
from typing import List, TextIO | |
def test_vbc(): | |
def test_vb_encode(numbers: List[int], ok: TextIO): | |
bytestream = vb.encode(numbers) | |
assert ''.join([format(b, '08b') for b in unpack('%dB' % len(bytestream), bytestream)]) == ok | |
print("test ok. %s -> %s" % (numbers, ok)) | |
test_vb_encode([1], '10000001') | |
test_vb_encode([5], '10000101') | |
test_vb_encode([127], '11111111') | |
test_vb_encode([128], '00000001' + '10000000') | |
test_vb_encode([129], '00000001' + '10000001') | |
test_vb_encode([1, 5], '10000001' + '10000101') | |
def test_vb_decode(): | |
n = random.randint(0, sys.maxsize) | |
assert vb.decode(vb.encode([n]))[0] == n | |
print("test ok. %s -> %s" % (n, n)) | |
test_vb_decode() | |
test_vbc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment