import os

import constants


def _split_encrypted(data: bytes):
    part_small_size = min(
        constants.SMALL_SIZE_KB * 1024, int(0.2 * len(data))
    )
    small = data[:part_small_size]
    big = data[part_small_size:]
    return small, big


def test_bt_spl_01_split_respects_size_constraint():
    data = os.urandom(10000)
    small, _ = _split_encrypted(data)
    cap = max(constants.SMALL_SIZE_KB * 1024, int(0.2 * len(data)))
    assert len(small) <= cap


def test_bt_spl_02_reassembly_equals_original():
    data = os.urandom(10000)
    small, big = _split_encrypted(data)
    assert small + big == data
