bin(num). convert ZERO and negative decimal numbers to binary.#1093
bin(num). convert ZERO and negative decimal numbers to binary.#1093cclauss merged 7 commits intoTheAlgorithms:masterfrom syedwaleedhyder:master
Conversation
…sistent with built-in python bin(x) function.
…sistent with built-in python bin(x) function.
|
No doctests?? :-( |
|
@syedwaleedhyder you can find information about writing doctests on Python's website. |
…s to binary. Consistent with built-in python bin(x) function.
|
Doctests added :) @cclauss @PatOnTheBack |
|
@syedwaleedhyder why are you testing |
…s to binary. Consistent with built-in python bin(x) function.
|
@PatOnTheBack Corrected. |
|
@PatOnTheBack How much time LGTM takes? |
…s to binary. Consistent with built-in python bin(x) function.
|
@cclauss Resolved. All test cases pass now. |
conversions/decimal_to_binary.py
Outdated
| """ | ||
| assert type(num) in (int, float) and num == int(num) | ||
|
|
||
| num = int(num) |
There was a problem hiding this comment.
The following test fails...
>>> decimal_to_binary(2.0) == bin(2.0)
True
There was a problem hiding this comment.
@cclauss bin(2.0) raises exception. And my code also raises exception. But the test still fails. Any idea how to resolve this issue? Can I just hard code the error in the doctests?
`**********************************************************************
File "decimal_to_binary.py", line 34, in main.decimal_to_binary
Failed example:
decimal_to_binary(2.0) == bin(2.0) # doctest: +ELLIPSIS
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python3.6/doctest.py", line 1330, in __run
compileflags, 1), test.globs)
File "<doctest main.decimal_to_binary[9]>", line 1, in
decimal_to_binary(2.0) == bin(2.0) # doctest: +ELLIPSIS
File "decimal_to_binary.py", line 38, in decimal_to_binary
raise TypeError("'float' object cannot be interpreted as an integer")
TypeError: 'float' object cannot be interpreted as an integer
`
|
# doctest: +ELLIPSIS as is done at Python/project_euler/problem_10/sol3.py Lines 31 to 38 in 4a5589f |
|
The exceptions do not have to be en exact match as long as the exception type and exception string are the same. |
|
Are we ready to merge? |
|
I think so. Still have a final look @cclauss . |
|
|
|
Thanks for your patience and persistence! |
|
Liked to work with you. Thanks. @cclauss |
…gorithms#1093) * bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * Added doctests. bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * Added doctests. bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * Added doctests. bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * doctests still failing. * Doctests added.
Fixes #1090
bin(num) in decimal_to_binary.py can now convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function.