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

feat: added random #140

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions src/random_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import random

Choose a reason for hiding this comment

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

Importa solo la funzione randint dal modulo random.


def rand()-> int:
numero_casuale = random.randint(1, 10)
print("Il numero casuale è:", numero_casuale)
return numero_casuale

def main():
rand()

if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions tests/test_random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
import random
from unittest.mock import patch
from src.random_1 import rand

def test_numero_5():
# Imposta un valore fisso per il random.randint
with patch.object(random, 'randint', return_value=5):
numero_casuale = rand()

assert numero_casuale == 5

def test_numero_10():
# Imposta un valore fisso per il random.randint
with patch.object(random, 'randint', return_value=10):
numero_casuale = rand()

assert numero_casuale == 10

def test_random_ce():
assert 1 <= rand() <= 10