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

Implement convert to binary #179

Open
wants to merge 2 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
4 changes: 4 additions & 0 deletions src/convert_to_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def convert_to_binary(value:int) -> str:
if(type(value) is int):
return bin(value)
return "ERRORE"
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 src.convert_to_binary as cbt
import pytest
from pytest_mock import MockerFixture

@pytest.mark.parametrize("input,expected,call_counter", [(10,"1010",1), (2.0, "ERRORE",0)])
def test_convert_to_binary(mocker: MockerFixture, input, expected, call_counter) -> None:
mock_value = "1010"
mocker.patch.object(cbt, "bin", return_value = mock_value)
spy = mocker.spy(cbt, "bin")

res= cbt.convert_to_binary(input)

assert res == expected
assert spy.call_count == call_counter
Loading