Skip to content

Commit 3c3a0b8

Browse files
authored
Use min() instead of of setting the floor for the RNG (#74)
1 parent 6946131 commit 3c3a0b8

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/inconnu/reference/resonance.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import inconnu
99
import services
1010
from ctx import AppCtx
11-
from inconnu import dice
1211
from models import ResonanceMode
1312
from utils import get_avatar
1413

@@ -118,7 +117,7 @@ async def _display_embed(
118117

119118
def _get_temperament(minimum=1) -> str:
120119
"""Randomgly generate a temperament."""
121-
die = dice.randint(minimum, 10)
120+
die = max(minimum, inconnu.d10())
122121

123122
if 1 <= die <= 5:
124123
return "Negligible"

tests/reference/test_resonance.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,21 @@
1919

2020
# Test _get_temperament
2121

22-
_RANDINT = "inconnu.reference.resonance.dice.randint"
2322
_D10 = "inconnu.d10"
2423

2524

2625
def test_get_temperament_negligible():
2726
"""Test _get_temperament returns Negligible for dice 1-5."""
2827
for die_value in range(1, 6):
29-
with patch(_RANDINT, return_value=die_value):
28+
with patch(_D10, return_value=die_value):
3029
result = _get_temperament()
3130
assert result == "Negligible"
3231

3332

3433
def test_get_temperament_fleeting():
3534
"""Test _get_temperament returns Fleeting for dice 6-8."""
3635
for die_value in range(6, 9):
37-
with patch(_RANDINT, return_value=die_value):
36+
with patch(_D10, return_value=die_value):
3837
result = _get_temperament()
3938
assert result == "Fleeting"
4039

@@ -43,7 +42,7 @@ def test_get_temperament_intense():
4342
"""Test _get_temperament returns Intense for 9-10 followed by 1-8."""
4443
for first_die in (9, 10):
4544
for second_die in range(1, 9):
46-
with patch(_RANDINT, return_value=first_die), patch(_D10, return_value=second_die):
45+
with patch(_D10, side_effect=[first_die, second_die]):
4746
result = _get_temperament()
4847
assert result == "Intense"
4948

@@ -52,7 +51,7 @@ def test_get_temperament_acute():
5251
"""Test _get_temperament returns Acute for 9-10 followed by 9-10."""
5352
for first_die in (9, 10):
5453
for second_die in (9, 10):
55-
with patch(_RANDINT, return_value=first_die), patch(_D10, return_value=second_die):
54+
with patch(_D10, side_effect=[first_die, second_die]):
5655
result = _get_temperament()
5756
assert result == "Acute"
5857

@@ -181,7 +180,7 @@ async def test_random_temperament():
181180
mock_mode.return_value = ResonanceMode.STANDARD
182181

183182
# Mock the temperament generation
184-
with patch(_RANDINT, return_value=7):
183+
with patch(_D10, return_value=7):
185184
await random_temperament(mock_ctx, "Choleric")
186185

187186
# Verify respond was called with an embed
@@ -209,7 +208,7 @@ async def test_random_temperament_negligible():
209208
mock_mode.return_value = ResonanceMode.STANDARD
210209

211210
# Mock negligible temperament
212-
with patch(_RANDINT, return_value=3):
211+
with patch(_D10, return_value=3):
213212
await random_temperament(mock_ctx, "Choleric")
214213

215214
mock_ctx.respond.assert_called_once()
@@ -232,7 +231,7 @@ async def test_resonance_with_temperament():
232231
mock_mode.return_value = ResonanceMode.STANDARD
233232

234233
# Mock fleeting temperament and choleric resonance
235-
with patch(_RANDINT, return_value=7), patch("inconnu.random", return_value=7):
234+
with patch(_D10, return_value=7), patch("inconnu.random", return_value=7):
236235
await resonance(mock_ctx)
237236

238237
mock_ctx.respond.assert_called_once()
@@ -255,7 +254,7 @@ async def test_resonance_negligible():
255254
mock_mode.return_value = ResonanceMode.STANDARD
256255

257256
# Mock negligible temperament
258-
with patch(_RANDINT, return_value=3):
257+
with patch(_D10, return_value=3):
259258
await resonance(mock_ctx)
260259

261260
mock_ctx.respond.assert_called_once()

0 commit comments

Comments
 (0)