Skip to content

Commit

Permalink
[iotaledger#49] trits_from_int now defaults to pad=1.
Browse files Browse the repository at this point in the history
  • Loading branch information
todofixthis committed Oct 14, 2017
1 parent bf08f6f commit 393d62d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions iota/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
TrytesCompatible = Union[AnyStr, bytearray, 'TryteString']


def trits_from_int(n, pad=None):
def trits_from_int(n, pad=1):
# type: (int, Optional[int]) -> List[int]
"""
Returns a trit representation of an integer value.
Expand All @@ -60,7 +60,7 @@ def trits_from_int(n, pad=None):
quotient += 1
remainder = -1

trits = [remainder] + trits_from_int(quotient)
trits = [remainder] + trits_from_int(quotient, pad=0)

if pad:
trits += [0] * max(0, pad - len(trits))
Expand Down
27 changes: 25 additions & 2 deletions test/types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,31 @@

from six import binary_type, text_type

from iota import Address, AddressChecksum, Hash, Tag, TryteString, TrytesCodec, \
TrytesDecodeError
from iota import Address, AddressChecksum, Hash, Tag, TryteString, \
TrytesCodec, TrytesDecodeError, trits_from_int


class TritsFromIntTestCase(TestCase):
"""
Explicit unit tests for :py:func:`trits_from_int`.
Note that this function is used internally by many different classes
and functions, so we still have good coverage even though this
particular test case has limited scope.
"""
def test_zero(self):
"""
Zero is represented as ``[0]`` by default.
https://github.com/iotaledger/iota.lib.py/issues/49
"""
self.assertEqual(trits_from_int(0), [0])

def test_zero_unpadded(self):
"""
Converting zero to trits, without padding.
"""
self.assertEqual(trits_from_int(0, pad=None), [])


# noinspection SpellCheckingInspection
Expand Down

0 comments on commit 393d62d

Please sign in to comment.