Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random number #178

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/random_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from random import randint

def random_number(min: int, max: int) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il nome delle variabili in questa maniera e' estremamente esplicito, pero' c'e' il problema che vanno a sovrascrivere (e quindi nascondere) le funzioni built-in di python, max e min, che quindi non potresti andare ad utilizzare all'interno della funzione.
Potresti quindi optare per nomi alternativi come min_value o minimum o puffo. Magari non l'ultimo. A meno che tu non sia Barbanera.

return randint(min, max)
5 changes: 5 additions & 0 deletions tests/test_random_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from src.random_number import random_number

def test_random_number() -> None:
t = random_number(0, 100)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dai un nome più "parlante" alla variabile t.
In questo contesto è ovviamente semplice da capire cosa contiene ma non è sempre così.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definisci delle variabili costanti che contengano 0 e 100.

assert t >= 0 and t <= 100
Comment on lines +4 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Volendo potresti mettere questo test in un ciclo giusto per fargli fare un po' di passate e vedere piu' output, ma essendo random in principio non cambia tantissimo

Loading