import xxhash


def test_compute_media_content_hash_small_file():
    # Arrange
    from media_hash import compute_media_content_hash

    data = b"x" * 100
    expected = xxhash.xxh64(len(data).to_bytes(8, "little") + data).hexdigest()
    # Act
    out = compute_media_content_hash(data)
    # Assert
    assert out == expected


def test_compute_media_content_hash_large_file():
    # Arrange
    from media_hash import compute_media_content_hash

    data = (bytes(range(256)) * 20)[:5000]
    n = len(data)
    mid = (n - 1024) // 2
    blob = (
        n.to_bytes(8, "little")
        + data[0:1024]
        + data[mid : mid + 1024]
        + data[-1024:]
    )
    expected = xxhash.xxh64(blob).hexdigest()
    # Act
    out = compute_media_content_hash(data)
    # Assert
    assert out == expected


def test_compute_media_content_hash_virtual_prefix():
    # Arrange
    from media_hash import compute_media_content_hash

    # Act
    v = compute_media_content_hash(b"abc", virtual=True)
    n = compute_media_content_hash(b"abc", virtual=False)
    # Assert
    assert v.startswith("V")
    assert not n.startswith("V")
    assert v == "V" + n
