Exemplo n.º 1
0
 def test_floats(self):
     assert fraction_to_key(0.0) == '0' * 64
     assert fraction_to_key(1.0) == 'f' * 64
     # This magic number is 0.00001 * 2**256, in hexadecimal
     assert (
         fraction_to_key(0.00001) ==
         '0000a7c5ac471b47880000000000000000000000000000000000000000000000')
Exemplo n.º 2
0
    def test_error_cases(self, bad_val):
        with pytest.raises(ValueError) as exc:
            fraction_to_key(bad_val)

        # Check that it is the expected error, not some spurious error from elsewhere.
        assert 'must be between 0 and 1 inclusive' in str(exc)
        # Check that the bad value is mentioned
        assert str(bad_val) in str(exc)
Exemplo n.º 3
0
    def test_error_cases(self, bad_val):
        with pytest.raises(ValueError) as exc:
            fraction_to_key(bad_val)

        # Check that it is the expected error, not some spurious error from elsewhere.
        assert "must be between 0 and 1 inclusive" in str(exc)
        # Check that the bad value is mentioned
        assert str(bad_val) in str(exc)
Exemplo n.º 4
0
 def test_exact(self):
     assert fraction_to_key(Fraction(0, 4)) == '0' * 64
     assert fraction_to_key(Fraction(1, 4)) == '3' + 'f' * 63
     assert fraction_to_key(Fraction(2, 4)) == '7' + 'f' * 63
     assert fraction_to_key(Fraction(3, 4)) == 'b' + 'f' * 63
     assert fraction_to_key(Fraction(4, 4)) == 'f' * 64
     assert fraction_to_key(Fraction(1, 32)) == '07' + 'f' * 62
Exemplo n.º 5
0
 def test_exact(self):
     assert fraction_to_key(Fraction(0, 4)) == '0' * 64
     assert fraction_to_key(Fraction(1, 4)) == '3' + 'f' * 63
     assert fraction_to_key(Fraction(2, 4)) == '7' + 'f' * 63
     assert fraction_to_key(Fraction(3, 4)) == 'b' + 'f' * 63
     assert fraction_to_key(Fraction(4, 4)) == 'f' * 64
     assert fraction_to_key(Fraction(1, 32)) == '07' + 'f' * 62
Exemplo n.º 6
0
 def test_exact(self):
     assert fraction_to_key(Fraction(0, 4)) == "0" * 64
     assert fraction_to_key(Fraction(1, 4)) == "3" + "f" * 63
     assert fraction_to_key(Fraction(2, 4)) == "7" + "f" * 63
     assert fraction_to_key(Fraction(3, 4)) == "b" + "f" * 63
     assert fraction_to_key(Fraction(4, 4)) == "f" * 64
     assert fraction_to_key(Fraction(1, 32)) == "07" + "f" * 62
Exemplo n.º 7
0
 def test_result_length(self):
     for _ in range(100):
         r = random()
         key = fraction_to_key(r)
         assert len(key) == 64
Exemplo n.º 8
0
 def test_floats(self):
     assert fraction_to_key(0.0) == '0' * 64
     assert fraction_to_key(1.0) == 'f' * 64
Exemplo n.º 9
0
 def test_exact(self):
     assert fraction_to_key(Fraction(0, 4)) == "0" * 64
     assert fraction_to_key(Fraction(1, 4)) == "3" + "f" * 63
     assert fraction_to_key(Fraction(2, 4)) == "7" + "f" * 63
     assert fraction_to_key(Fraction(3, 4)) == "b" + "f" * 63
     assert fraction_to_key(Fraction(4, 4)) == "f" * 64
Exemplo n.º 10
0
 def test_result_length(self):
     for _ in range(100):
         r = random()
         key = fraction_to_key(r)
         assert len(key) == 64
Exemplo n.º 11
0
 def test_floats(self):
     assert fraction_to_key(0.0) == "0" * 64
     assert fraction_to_key(1.0) == "f" * 64
Exemplo n.º 12
0
 def test_floats(self):
     assert fraction_to_key(0.0) == '0' * 64
     assert fraction_to_key(1.0) == 'f' * 64
     # This magic number is 0.00001 * 2**256, in hexadecimal
     assert (fraction_to_key(0.00001) ==
             '0000a7c5ac471b47880000000000000000000000000000000000000000000000')