Example #1
0
    def height(self):
        """Current height of the Merkle-tree

        .. note:: Since the tree is binary *balanced*, its height coincides
                with the length of its leftmost branch

        :rtype: int
        """
        length = len(self.leaves)
        if length == 0:
            return 0
        return log_2(length) + 1 if length != 2 ** log_2(length) \
            else log_2(length)
Example #2
0
def test_log_2(num, expected):
    """Tests log_2 evaluations for all possible combination of powers from 0 to 10
    """

    assert utils.log_2(num) == expected
Example #3
0
def test_log_2_zero_convention():
    """Tests that log_2 evaluates to 0 for the zero argument
    """

    assert utils.log_2(0) == 0
Example #4
0
def test_log_2_exception():
    """Tests that log_2 raises ValueError for negative arguments
    """

    with pytest.raises(ValueError):
        utils.log_2(-1)