Skip to content
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
11 changes: 11 additions & 0 deletions src/convert_to_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Write a program that given a number as input convert it in binary.
#
# Output:
# Insert first number: 8
# The binary number is: 1000
#
def convert_to_binary():
n = int(input("Insert first number: "))
print("The binary number is:" , bin(n)[2:])
convert_to_binary()
7 changes: 7 additions & 0 deletions src/random_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
# Output:
# The random number is: 4
#
import random
def generator_number():
number = int(input("Inserisci un numero: "))
number = random.randint(1, number)
print("Il numero casuale e': ", number)
return number
generator_number()
14 changes: 14 additions & 0 deletions tests/test_convert_to_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest
from unittest.mock import patch
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

bisogna usare pytest non unittest

from io import StringIO
from src.convert_to_binary import convert_to_binary

class TestConvertToBinary(unittest.TestCase):
@patch("builtins.input", return_value="5")
@patch("sys.stdout", new_callable=StringIO)
def test_convert_to_binary(self, mock_stdout, mock_input):
convert_to_binary()
output = mock_stdout.getvalue().strip()
self.assertEqual(output, "The binary number is: 101")
if __name__ == "__main__":
unittest.main()
Loading