import pytest
from app.functions.roll_dices import roll_dices
from unittest.mock import patch


@patch('random.randint')
def test_roll_dices_no_discard(mock_randint):
    # mocks
    mock_randint.return_value = 4

    # Test with discard_lowest = False
    result = roll_dices(4, 6, False)
    assert 'dice-set' in result
    assert 'rolls' in result
    assert 'result' in result
    assert len(result['rolls']) == 4
    assert 'discarded' not in result

    mnemonic = result['dice-set']['mnemonic']
    assert mnemonic == '4d6'


@patch('random.randint')
def test_roll_dices_with_discard(mock_randint):
    # mocks
    mock_randint.return_value = 4

    # Test with discard_lowest = True
    result = roll_dices(4, 6, True)
    assert 'dice-set' in result
    assert 'rolls' in result
    assert 'result' in result
    assert len(result['rolls']) == 3
    assert 'discarded' in result
    assert len(result['discarded']) == 1

    mnemonic = result['dice-set']['mnemonic']
    assert mnemonic == '4(-1)d6'
