import pathlib

import numpy as np

from src.repositories.battleList.core import getCreaturesHpPercentages
from src.utils.image import loadFromRGBToGray


def test_full_bar_reads_hundred_percent():
    fixture = (
        pathlib.Path(__file__).parent
        / 'getFilledSlotsCount' / 'fullCreaturesInBattleListContent.png'
    )
    content = loadFromRGBToGray(str(fixture))

    hps = getCreaturesHpPercentages(content, 3)

    assert hps == [99, 99, 99]


def test_half_filled_bar_reads_fifty_percent():
    content = np.zeros((22, 156), dtype=np.uint8)
    content[17, 22:87] = 192  # 65 von 130 Balkenpixeln

    hps = getCreaturesHpPercentages(content, 1)

    assert hps == [50]


def test_missing_bar_reads_none():
    content = np.zeros((10, 50), dtype=np.uint8)

    assert getCreaturesHpPercentages(content, 1) == [None]
